Home > Backend Development > PHP Tutorial > Usage example of intercepting string length in PHP

Usage example of intercepting string length in PHP

高洛峰
Release: 2023-03-04 20:06:01
Original
1206 people have browsed it

The example of this article describes the usage of intercepting the length of string in PHP. Share it with everyone for your reference, the details are as follows:

php provides many functions, among which the string interception function is no exception, and the function is also very powerful.

<?php
//文件编码格式为UTF-8
$str=&#39;在公园船上,有一个漂亮的女孩,如果在湖中央发生点什么……&#39;;
echo mb_substr($str,0,7,&#39;UTF-8&#39;);//这里设置显示字符串的编码格式 //输出&#39;在公园船上,有&#39;
echo mb_substr($str,3,7,&#39;UTF-8&#39;);//这里设置显示字符串的编码格式 //输出&#39;船上,有一个漂&#39;
?>
Copy after login

You must pay attention to the encoding format here. Improper handling may cause garbled characters.

I hope this article will be helpful to everyone in PHP programming.

For more related articles about string length interception usage examples in PHP, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template