html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

C_substr_PHP教程_编程技术

[ ] 已经帮助:人解决问题

<?
//用法与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 < 0)
    $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);
}
?>

VSfHTML5中文学习网 - HTML5先行者学习网
VSfHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助