Home > Backend Development > PHP Tutorial > PHP 实现explort() 功能的详解_PHP

PHP 实现explort() 功能的详解_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 12:06:14
Original
1184 people have browsed it
复制代码 代码如下:
/**
 * PHP 实现explort() 功能的详解
 */
$str = ',1,2,3,4,321321,aaa,bbb';
function myExplode($seg,$str,$limit=0){
   $_ret = array(0=>'');
   $len = strlen($str);
   $slen = strlen($seg);
   $_limit = 0;
   for($i=0; $i      if(substr($str,$i,$slen) == $seg ){
          $_limit++;
          $i += $slen-1;
          continue;
      }else{
          $_ret[$_limit] .= $str[$i];
      }
   }
   if($limit       $_ret = array_slice($_ret, 0 , $limit );
   else{
      $_ret = $limit >= count($_ret) ? $_ret :  array_merge(array_slice($_ret, 0 , $limit-1 ), array(implode( $seg , array_slice($_ret,$limit-1))));
   }
   return $_ret;
}
var_dump(myExplode("4",$str));
echo "
";
var_dump(explode("4",$str));
echo "
";
?>

支持 limit 为负。。分割符为字符串
Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template