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 converts a string that exceeds the length of $ len to "and remove garbled characters. Usage: $ newgetsubstring ($ old, 20); functiongetsubstring ($ str, $ l SUBSTR
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 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 ."...";
}