PHP截取中文字符串方法
经过测试比其他的好
php utf-8 字符串截取
<?php
    function cutstr($string, $length) {
        preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $info);
        for($i=0; $i<count($info[0]); $i++) {
            $wordscut .= $info[0][$i];
            $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
            if ($j > $length – 3) {
                return $wordscut." …";
            }
        }
        return join(", $info[0]);
    }
    $string="242432反对感是456犯得上广泛大使馆地方7890";
    for($i=0;$i<strlen($string);$i++)
    {
        echo cutstr($string,$i)."<br>";
    }
?>
本条目发布于2010年9月3日。属于小功能分类。