Home  >  Article  >  Backend Development  >  php中输出中文字符乱码解决方案

php中输出中文字符乱码解决方案

WBOY
WBOYOriginal
2016-06-13 11:47:05929browse

php中输出中文字符乱码
问题如下:
$load_list 是一个二维数组,将其中的user_name值取出前两个字符,后面用星号代替,但是遇到中文字符就出现乱码,设置header()函数,也没用,求解决办法,谢谢!
foreach($load_list as $k=>&$v){
 $temp=&$v['user_name'];

 for($i=0,$len=strlen($temp);$i if($i>1){
  $temp[$i]='*';
}
 }
}

截图如下:
------解决方案--------------------
你的代码只适用于单字节字符串,没有考虑到
中文 gbk 一个字符 2 个字节
中文 utf-8 一个字符 3 个字节
------解决方案--------------------
试试mb_substr函数

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