// A function in php that controls string output (Chinese and English), how many words are displayed in each line, to avoid the influence of English
// $str string
// $len The number of characters displayed in each line (Chinese characters × 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;
}
The above has introduced the functions that control string output in PHP, including the content of controlling string functions. I hope it will be helpful to friends who are interested in PHP tutorials.