The substr () function Chinese version of the normal substr () function can get a string of a specified length substring, but encountered in Chinese can be garbled at the end of a new string, the following function will be more than $len length of the string converted to "..." end, and removed garbled.
Usage: $new = getsubstring ($old, 20);
function getsubstring ($STR, $len)
{
for ($i = 0; $i < $end; $i + +)
{
if ($i >=0 and $i < $end)
{
if (Ord (substr ($str, $i, 1)) > 0xa1)
$result _str.=substr ($str, $i, 2);
Else
$result _str.=substr ($str, $i, 1);
}
if (Ord (substr ($str, $i, 1)) > 0xa1)
$i + +;
}
if (strlen ($STR) <= $end)
return $result _str;
Else
return $result _str. " ...";
}
http://www.bkjia.com/PHPjc/314531.html www.bkjia.com true http://www.bkjia.com/PHPjc/314531.html techarticle The substr () function Chinese version of the normal substr () function can get a string of a specified length substring, but encountered in Chinese can be garbled at the end of a new string, the following function will be super ...