php截取utf-8中文字符串乱码的解决方法
更新时间:2010年03月29日 20:52:35 作者:
在PHP中截取UTF-8编码的字符串时,有可能碰到半字符的问题,也就是乱码,以下函数可以解决这个问题
复制代码 代码如下:
function utf8_substr($str,$len)
{
for($i=0;$i<$len;$i++)
{
$temp_str=substr($str,0,1);
if(ord($temp_str) > 127){
$i++;
if($i<$len){
$new_str[]=substr($str,0,3);
$str=substr($str,3);
}
}else {
$new_str[]=substr($str,0,1);
$str=substr($str,1);
}
}
return join($new_str);
}
您可能感兴趣的文章:
相关文章
PHP file_get_contents 函数超时的几种解决方法
在使用file_get_contents函数的时候,经常会出现超时的情况,在这里要通过查看一下错误提示,看看是哪种错误,比较常见的是读取超时,这种情况大家可以通过一些方法来尽量的避免或者解决。2009-07-07
最新评论