欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決中英文字符串長(zhǎng)度問(wèn)題函數(shù)

 更新時(shí)間:2007年01月16日 00:00:00   作者:  
復(fù)制代碼 代碼如下:

function strSplit($s, $len) {
    $end = '…';
    $result = '';
    $strLen = strlen($s);
    if ($strLen <= $len) {
        return $s;
    }
    $len -= 2;
    for ($i=0; $i<$len && $i<$strLen; $i++) {
        $c = $s[$i];
        if (ord($c) < 0x80) {
            $result .= $c;
        } elseif ($i+1<$len) {
            $result .= $s[$i++] . $s[$i];
        }
    }
    return ($i < $strLen) ? ($result . $end) : $result;
}

echo strSplit('1234567', 10), '<br />';
echo strSplit('1234567890', 10), '<br />';
echo strSplit('1234中文567890abcdefghijkl', 10), '<br />';
echo strSplit('全部都是中文', 10), '<br />';
echo strSplit('全a部b都c是d中e文', 10), '<br />'; 

輸出:
1234567
1234567890
1234中文…
全部都是…
全a部b都… 

相關(guān)文章

最新評(píng)論