Home >Backend Development >PHP Tutorial >Usage example of intercepting string length in PHP
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='在公园船上,有一个漂亮的女孩,如果在湖中央发生点什么……'; echo mb_substr($str,0,7,'UTF-8');//这里设置显示字符串的编码格式 //输出'在公园船上,有' echo mb_substr($str,3,7,'UTF-8');//这里设置显示字符串的编码格式 //输出'船上,有一个漂' ?>
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!