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 tag: 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 ."...";
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.