//截取字符串(中英文都按一个字符计算)
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;
}
示例:
echo c_substr('截取字符串',0,3);