Home >Backend Development >PHP Tutorial >Application method of PHP mb_substr function in actual coding_PHP tutorial

Application method of PHP mb_substr function in actual coding_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:31:22855browse

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.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446218.htmlTechArticleWe are using 1. Make sure you have the file php_mbstring.dll under Windows/system32. If not, just use Php Copy the installation directory extensions into Windows/system32. 2. Find in the windows directory...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn