The use of a few character functions such as mb_substr is not very easy to use, or this is more useful. [Php]/*** truncation function to prevent garbled characters ***/functionz_substr ($ sourcestr = & amp; #39; & amp; #39;, $ I = 0, $ cutlength = 150, $ endstr = & amp; #39; & amp; #39;) {$
The use of a few character functions such as mb_substr is not very easy to use, or this is more useful.
[Php]
/**
* Truncation function to prevent garbled characters
*
*
*/
Function z_substr ($ sourcestr = '', $ I = 0, $ cutlength = 150, $ endstr = '')
{
$ Str_length = strlen ($ sourcestr); // Number of bytes of the string
While ($ n <$ cutlength) and ($ I <= $ str_length ))
{
$ Temp_str = substr ($ sourcestr, $ I, 1 );
$ Ascnum = Ord ($ temp_str); // ascii code
If ($ ascnum> = 224)
{
$ Returnstr = $ returnstr. substr ($ sourcestr, $ I, 3 );
$ I = $ I + 3;
$ N ++;
} Elseif ($ ascnum >=192)
{
$ Returnstr = $ returnstr. substr ($ sourcestr, $ I, 2 );
$ I = $ I + 2;
$ N ++;
} Else
{
$ Returnstr = $ returnstr. substr ($ sourcestr, $ I, 1 );
$ I = $ I + 1;
$ N = $ n + 0.5;
}
}
If ($ I <$ str_length) $ returnstr. = $ endstr;
Return $ returnstr;
}