Home >Backend Development >PHP Tutorial >字符串截取问题请教

字符串截取问题请教

WBOY
WBOYOriginal
2016-06-23 14:27:491021browse

$str="销售";
$str="销售在在大";
$str="销夺基本原则";
$str="左枯在";

echo substr($str,1);

为什么显示是乱码?
在网上搜了一些解决方法 http://www.111cn.net/phper/php-cy/35494.htm 都不行,还是显示乱码。大神帮下我,这个问题应该如何解决 ,我的gbk编码


回复讨论(解决方案)

因为substr无法处理unicode字符串……

try mb_substr()

试了还是一样乱码

mb_internal_encoding("GBK");

echo mb_substr($str,1);

utf8   和 gbk编码 截取字符串的方法不同的

网页的编码和网页内容的编码要一致

$str="销夺基本原则";
echo mb_substr($str,1,6,"gb2312");

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