Php code for a Chinese string truncation function in PHP:
--------------------------------------------------------------------------------
/**
* ** @ Author: Glad
* ** @ URL: http://www.cnpik.com/
* ** @ E_mail: lianxiwoo@sohu.com
* ** @ Use it as needed. do not collect the money :-)
*/
Function cnSubStr ($ string, $ sublen)
{
If ($ sublen> = strlen ($ string ))
{
Return $ string;
}
$ S = "";
For ($ I = 0; $ I <$ sublen; $ I ++)
{
If (ord ($ string {$ I})> 127)
{
$ S. =$ string {$ I}. $ string {++ $ I };
Continue;
} Else {
$ S. =$ string {$ I };
Continue;
}
}
Return $ s;
} // End Function cnSubStr ($ string, $ sublen)
///// // Use like this:
Echo"
__________________________
";
$ String = "242432 objection: 456 the attack against a wide range of embassy places 7890 ";
$ Sublen = strlen ($ string );
$ Len = 20;
Echo $ string ."
";
Echo "Total length:". ($ sublen + 1 )."
";
Echo "number of interceptions:". $ len ."
";
For ($ I = 1; $ I <= $ sublen + 1; $ I ++ ){
If ($ I> $ len ){
Echo $ I ."→". CnSubStr ($ string, $ I )."...
";
Continue;
}
Echo $ I ."→". CnSubStr ($ string, $ I )."
";
}
?>