Php string truncation function. This article introduces a function provided by php to intercept strings. it can only process English characters and numbers cannot intercept Chinese characters. if you need it, you can refer to the function, this article introduces a function provided by php to intercept strings. it can only process English characters and numbers cannot intercept Chinese characters. if you need it, you can refer to the function, the first is intended for beginners.
| The code is as follows: |
|
/*
------------------------------------------------------
Parameters:
$ Str_cut: string to be truncated
$ Length: maximum length allowed for string display
Program function: Intercept character strings mixed with full-width and half-width characters (Chinese characters and English characters) to avoid garbled characters
------------------------------------------------------
*/
Function substr_cut ($ str_cut, $ length)
{
If (strlen ($ str_cut)> $ length)
{
For ($ I = 0; $ I <$ length; $ I ++)
If (ord ($ str_cut [$ I])> 128) $ I ++;
$ Str_cut = substr ($ str_cut, 0, $ I )."..";
}
Return $ str_cut;
}
?> |
Success ,...