Solution to php mbsubstr garbled code: First find php.ini in the windows directory; then find ";extension=php_mbstring.dll" and remove the preceding semicolon.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
Solution to the problem of garbled Chinese characters intercepted by PHP Application of mb_substr function
Using mb_substr to intercept strings will not cause garbled characters, and experts can fly...
First of all
1. Make sure you have the php_mbstring.dll file under 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, and the mb_strcut function can also You can intercept the length of the string. Let’s see the difference in the following example:
The code is as follows:
<?php $str = '这样一来我的字符串就不会有乱码^_^'; echo "mb_substr:" . mb_substr($str, 0, 7, 'utf-8'); //结果:这样一来我的字 echo "<br>"; echo "mb_strcut:" . mb_strcut($str, 0, 6, 'utf-8'); //结果:这样 ?>
As can be seen from the above example, mb_substr divides characters by words, while mb_strcut Characters are divided by bytes, but half characters will not be produced.
Recommended: "PHP Video Tutorial"
The above is the detailed content of How to solve the php mbsubstr garbled problem. For more information, please follow other related articles on the PHP Chinese website!