妙哉,绝哉~~~

      PHP 2004-12-21 15:49
中文字符截取完美解决方案
引用:
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共

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}