We are using 1. Make sure you have the file php_mbstring.dll 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
PHP mb_substr function can also intercept the length of the string. Let’s see the difference in the following example:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">str</span><span> =</span><span class="attribute-value">'这样一来我的字符串就不会有乱码^_^'</span><span>; </span></li><li class="alt"><span>echo"mb_substr:".mb_substr($str,0,7,'utf-8'); </span></li><li><span>//结果:这样一来我的字 </span></li><li class="alt"><span>echo"</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span class="tag">></span><span>"; </span></span></li> <li><span>echo"mb_strcut:".mb_strcut($str,0,6,'utf-8'); </span></li> <li class="alt"><span>//结果:这样 </span></li> <li> <span class="tag">?></span><span> </span> </li> <li class="alt"><span> </span></li> </ol>
As can be seen from the above example, The PHP mb_substr function splits characters by words, while mb_strcut splits characters by bytes, but neither will produce half a character.