Substr () function Chinese version. Substr () function Chinese normal substr () function can obtain the specified length of the string, but in case of Chinese, garbled characters may be generated at the end of the new string, the following function returns the substr () substr of the Chinese version of the substr () function to obtain the specified length of the substring. However, garbled characters may be generated at the end of the new substring in the case of Chinese characters, the following function converts a string that exceeds the length of $ len to "and remove 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 );
}
If (ord (substr ($ str, $ I, 1)> 0xa1)
$ I ++;
}
If (strlen ($ str) <= $ end)
Return $ result_str;
Else
Return $ result_str ."...";
}
The http://www.bkjia.com/PHPjc/314531.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/314531.htmlTechArticlesubstr () function Chinese common substr () function can get the specified length of the string substring, but in the case of Chinese, it may produce garbled characters at the end of the new string, the following function will overwrite...