PHP中一个控制字符串输出的函数

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
// PHP 中 一个控制字符串输出的函数(中英文),每行显示多少字数,避免英文的影响
// $str 字符串
// $len 每行显示的字数(汉字㗲)


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.="<BR>";
              $pos=0;
              break;
             case 10:                
              $pos=0;
              break;              
             case 32;              
                 $finstr.="&nbsp;";
                 $pos++;
                 break;
             default:                       
              $finstr.=htmlspecialchars($s1);  
              $pos++;     
              break;
          }       
           
          $i++;  
           
       } //if
     
    if($pos>=$len){     
          $finstr.="<BR>";
          $pos=0;
    }




    }  //while
    return $finstr;   
}   
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
文章标签: php function
个人分类: 网络技术
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭