Home >Backend Development >PHP Tutorial >A function to control string output in PHP_PHP tutorial

A function to control string output in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:02:09803browse

// 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 words 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:
$fin str.="
";
                                                                                           break; break;
case 32;
$finstr.=" ";
                  $pos++;                                       chars($s1);
$pos++;
break;

$i++ ;

} //if

if($pos>=$len){
$finstr.="
";
$pos=0;
}




} //while
return $finstr;
}




http://www.bkjia.com/PHPjc/316636.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/316636.html

// A function in php that controls string output (Chinese and English), how many words are displayed in each line, and avoids English Influence // $str string // $len Number of words displayed in each line (Chinese characters × 2) func...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn