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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 16:02:09
Original
844 people have browsed it

// 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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template