中文字符截取完美解决方案
引用:
function c_substr($string, $from, $length = null){
preg_match_all('/[\x80-\xff]?./', $string, $match);
if(is_null($length)){
$result = implode('', array_slice($match[0], $from));
}else{
$result = implode('', array_slice($match[0], $from, $length));
}
return $result;
}
$str = "zhon华人min共和guo";
$from = 3;
$length = 7;
echo(c_substr($str, $from, $length));
// 输出:n华人min共
回复Comments
作者:
{commentrecontent}