自己又写了个截取中文字符串的函数

自己又写了个截取中文字符串的函数
$s=”[北京的金山上]”;
function ch_left($s, $len){
    if(strlen($s)>$len)
        $s=substr($s, 0, $len);
    $ch='[‘.chr(0x81)-chr(0xff).’]’;
    if(preg_match(“/$ch($ch{2})*$/”, $s))
        $s=substr($s,0,-1);
    return $s;
}
echo ch_left($s,8);
?>

1 thought on “自己又写了个截取中文字符串的函数

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.