Home >Backend Development >PHP Tutorial >Application of mb_substr function to solve the problem of garbled Chinese characters intercepted by PHP
1. First, make sure you have the file php_mbstring.dll in Windows/system32. If not, copy it from your Php installation directory extensions into Windows/system32.
2. Find php.ini in the windows directory, open it for editing, search for mbstring.dll, find
;extension=php_mbstring.dll, and remove the ; sign in front, so that the mb_substr function can take effect. The mb_strcut function can also intercept strings. Length, let’s see the difference in detail in the following example:
<?php $str = '这样一来我的字符串就不会有乱码^_^'; echo "mb_substr:" . mb_substr($str, 0, 7, 'utf-8'); //结果:这样一来我的字 echo " "; echo "mb_strcut:" . mb_strcut($str, 0, 6, 'utf-8'); //结果:这样 ?>As can be seen from the above example, mb_substr splits characters by words, while mb_strcut splits characters by bytes, but both There will be no half-character phenomenon. The above introduces the application of the mb_substr function, a solution to the problem of intercepting garbled Chinese characters in PHP. I hope it will be helpful to friends who are interested in PHP tutorials.