This article mainly introduces the usage of intercepting string length in PHP, and analyzes the relevant operating techniques and precautions for the mb_substr function to intercept Chinese strings in the form of examples. Friends in need can refer to this article
The example describes the usage of intercepting the string length 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.
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHPStringReverse order implementation method
php implements the method of obtaining a specified number of random strings
php implements custom interception of Chinese strings -utf8 version
The above is the detailed content of Detailed explanation of how to intercept string length in PHP. For more information, please follow other related articles on the PHP Chinese website!