Home > php教程 > php手册 > PHP截取汉字乱码问题解决方法mb_substr函数的应用

PHP截取汉字乱码问题解决方法mb_substr函数的应用

WBOY
Release: 2016-06-13 12:29:55
Original
1174 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函数就可以生效了
mb_strcut函数功能也可以截取字符串长度,下面实例具体看看区别在哪:

复制代码 代码如下:


$str = '这样一来我的字符串就不会有乱码^_^';

echo "mb_substr:" . mb_substr($str, 0, 7, 'utf-8');
//结果:这样一来我的字
echo "
";

echo "mb_strcut:" . mb_strcut($str, 0, 6, 'utf-8');
//结果:这样
?>



从上面的例子可以看出,mb_substr是按字来切分字符,而mb_strcut是按字节来切分字符,但是都不会产生半个字符的现象。
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template