Home > php教程 > php手册 > PHP mb_substr函数在实际编码中的应用方法

PHP mb_substr函数在实际编码中的应用方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:08:19
Original
936 people have browsed it

我们在使用1.确保你的Windows/system32下有php_mbstring.dll这个文件,没有就从你Php安装目录extensions里拷入Windows/system32里面。

2.在windows目录下找到php.ini打开编辑,搜索mbstring.dll,找到;extension=php_mbstring.dll把前面的;号去掉,这样mb_substr函数就可以生效了

PHP mb_substr函数功能也可以截取字符串长度,下面实例具体看看区别在哪:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php  </span></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 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>
Copy after login

从上面的例子可以看出,PHP mb_substr函数是按字来切分字符,而mb_strcut是按字节来切分字符,但是都不会产生半个字符的现象。


Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template