Function to control string output in PHP

WBOY
Release: 2016-08-08 09:34:04
Original
1047 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 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.


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template