substr() function Chinese version
The ordinary substr() function can obtain a substring of a specified length of a string, but when encountering Chinese, garbled characters may be generated at the end of the new string. The following function converts a string longer than $len into a string with "... "End, and remove the garbled characters.
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);
}
🎜> return $result_str;
http://www.bkjia.com/PHPjc/314531.html
www.bkjia.com