Copy CodeThe code is as follows:
/**
* PHP Implementation Explort () function of the detailed
*/
$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 < $len; $i + +) {
if (substr ($str, $i, $slen) = = $seg) {
$_limit++;
$i + = $slen-1;
Continue
}else{
$_ret[$_limit]. = $str [$i];
}
}
if ($limit < 0)
$_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 "
";
?>
Support limit is negative. Delimiter is a string
http://www.bkjia.com/PHPjc/327728.html www.bkjia.com true http://www.bkjia.com/PHPjc/327728.html techarticle Copy the code as follows: PHP/** * PHP Implementation Explort () function of the detailed * * $str = ', 1,2,3,4,321321,aaa,bbb '; function Myexplode ($seg, $str, $limit =0 {$_ret = array (0= "); $len = S ...