Home >php教程 >PHP源码 >php 字符截取函数

php 字符截取函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:29:251122browse
<script>ec(2);</script>

php 字符截取函数

function sub_str($title,$lengh){
 if(strlen($title)>$lengh)
 {
  $pp=2;
  $len=strlen($title);
  if($len%20)
  {$pp=1;}
  $title=substr($title,0,$lengh-$pp);
  $title=$title.' …';
 }
 return $title;
}


//--------------------------------------字符截取函数2
function sub($Modi_Str,$start,$length,$mode = false){
 $n = 0;
 for($i=0;$i   if(ord(substr($Modi_Str,$i,1))>0xa0){
   if($mode){
    $start++;
    $i++;
   }
   $n++;
  }
 }
 if(!$mode)$start = $start + $n%2;
 $The_length = $start+$length;
 for($i=$start;$i   if(ord(substr($Modi_Str,$i,1))>0xa0){
   $The_Str.=substr($Modi_Str,$i,2);
   $i++;
   if($mode) $The_length++;
  }else{
   $The_Str.=substr($Modi_Str,$i,1);
  }
 }
 return $The_Str;
}

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