A function (in Chinese and English) that controls the output of a string in php. the number of words displayed in each line is avoided. $ str string $ len: the number of words displayed in each line (Chinese character × 2) functionrep ($ str, $ len) {& nbsp; $ strlenstrlen ($ str); & nbsp; $ i0; $ finstr & quot; & qu // a function in php that controls the output of strings (in Chinese and English). The number of words displayed in each line avoids the influence of English.
// $ Str string
// $ Len the number of words displayed per line (Chinese character × 2)
Function rep ($ str, $ len)
{
$ Strlen = strlen ($ str );
$ I = 0;
$ Finstr = "";
$ Pos = 0;
While ($ I <$ strlen)
{
$ S1 = substr ($ str, $ I, 1 );
$ S2 = ord ($ s1 );
If ($ s2> 0xa0 ){
$ Finstr. = substr ($ str, $ I, 2 );
$ Pos + = 2;
$ I + = 2;
} Else {
Switch ($ s2 ){
Case 13:
$ Finstr. ="
";
$ Pos = 0;
Break;
Case 10:
$ Pos = 0;
Break;
Case 32;
$ Finstr. = "";
$ Pos ++;
Break;
Default:
$ Finstr. = htmlspecialchars ($ s1 );
$ Pos ++;
Break;
}
$ I ++;
} // If
If ($ pos >=$ len ){
$ Finstr. ="
";
$ Pos = 0;
}
} // While
Return $ finstr;
}