Home > php教程 > php手册 > C_substr

C_substr

WBOY
Release: 2016-06-21 09:06:57
Original
1090 people have browsed it


//用法与substr函数一样
function c_substr($str,$start=0) {
  $ch = chr(127);
  $p = array("/[\x81-\xfe]([\x81-\xfe]|[\x40-\xfe])/","/[\x01-\x77]/");
  $r = array("","");
  if(func_num_args() > 2)
    $end = func_get_arg(2);
  else
    $end = strlen($str);
  if($start     $start += $end;

  if($start > 0) {
    $s = substr($str,0,$start);
    if($s[strlen($s)-1] > $ch) {
      $s = preg_replace($p,$r,$s);
    $start += strlen($s);
    }
  }
  $s = substr($str,$start,$end);
  $end = strlen($s);
  if($s[$end-1] > $ch) {
    $s = preg_replace($p,$r,$s);
    $end += strlen($s);
  }
  return substr($str,$start,$end);
}
?>



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