The solution to php intercepting garbled Chinese strings: first create a PHP sample file; then use the "mb_strlen($str, $encoding)" method to solve the garbled problem.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What to do if php intercepts garbled Chinese strings ?
Solution to garbled characters when intercepting Chinese strings with PHP
When there is a need to intercept strings, the first thing that comes to mind is substr(), but there will be problems with garbled characters. So if To intercept Chinese strings, you can use PHP's built-in function Chinese interception: mb_substr(), which is
mb_substr( $str, $start, $length, $encoding )
$str: the Chinese string that needs to be intercepted;
$start: the start of interception Parameters, starting at 0;
$length: the number of words to be intercepted;
$encoding: web page encoding, such as UTF-8, GB2312, GBK;
Additionally attached The previous function to get the Chinese string length is to get the Chinese length: mb_strlen()
mb_strlen( $str, $encoding ) $str : 中文字符串 ; $encoding : 网页编码,如UTF-8,GB2312,GBK;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if PHP intercepts garbled Chinese strings. For more information, please follow other related articles on the PHP Chinese website!