FunctioncsubStr ($ str, $ start, $ len) {$ strlenstrlen ($ str); $ clen0; for ($ i0; $ I $ start + $ len) break; if (ord (substr ($ str, $ I, 1) 0xa0) {if ($ clen $ start) $ tmpstr. substr ($ str, $ I, 2)
Function csubStr ($ str, $ start, $ len)
{
$ Strlen = strlen ($ str );
$ Clen = 0;
For ($ I = 0; $ I <$ strlen; $ I ++, $ clen ++)
{
If ($ clen >=$ start + $ len)
Break;
If (ord (substr ($ str, $ I, 1)> 0xa0)
{
If ($ clen> = $ start)
$ Tmpstr. = substr ($ str, $ I, 2 );
$ I ++;
}
Else
{
If ($ clen> = $ start)
$ Tmpstr. = substr ($ str, $ I, 1 );
}
}
Return $ tmpstr;
}
Example: $ str = csubStr ("Hello everyone, take the string of the specified number of words, 886! ", 0, 10 );
This function is usually used to display the list of forum topics. for example, you can use the following function:
Function showShort ($ str, $ len)
{
If ($ len <(strlen ($ str)/2 ))
{
$ TempStr = csubStr ($ str, 0, $ len );
$ TempStr. = "...";
}
Else
{
$ TempStr = $ str;
}
Return $ tempStr;
}
When the topic exceeds the specified number of words, it is intercepted and a ellipsis is added. Otherwise, all words are displayed.
Eclipse replied: 21:39:31 [B] [color = red] is not very useful? [/Color] [/B]
Bigmouse replied: 12:02:54 is still useful. if you do not judge whether the Chinese byte is intercepted, garbled characters will occur when it is captured to the middle of the Chinese character. after all, the Chinese character is dubyte, make a special judgment.
The response from edevil is as follows: 11:42:07 mb_substr.
Wubai replied to: 11:49:03
Let's take a look at this ~~~~~
Http://www.chinaunix.net/cgi-bin/bbs/topic.cgi? Forum = 15 & topic = 351 & show = 0
Windlike replied to: 15:13:29 good. This Post launched well. I can use it right away. thank you very much.