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

php 字符截取函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:29:25
Original
1115 people have browsed it
<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;
}

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