Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- "recriando a roda", função explode()
- By: Papadópolis (@papadopolis)
- */
- function _explode($op,$str,$lim = null) {
- $output = array();
- preg_match_all("/(.*?$op|.*?$)/i",$str,$vals);
- unset($vals[0],$vals[1][count($vals[1])-1]);
- foreach($vals as $ind => $val)
- foreach($val as $exe)
- $output[] = str_replace($op,"",$exe);
- if($lim !== null) {
- if($lim>=0) {
- $alg = array();
- $tmp = $output;
- $co = 0;
- for(;;) {
- $alg[] = $output[$co];
- unset($tmp[$co]);
- if($co == $lim-1) {
- foreach($tmp as $val)
- $alg[$co] .= sprintf("%s%s",$op,$val);
- break;
- }
- ++$co;
- }
- $output = $alg;
- } else {
- $f = count($output)-1;
- $l = $f-substr($lim,1);
- for(;;) {
- unset($output[$f]);
- --$f;
- if($f == $l) break;
- }
- }
- }
- return $output;
- }
- $str = "a,e,i,o,u,1,2,3,4,5";
- $str = _explode(",",$str,3);
- print_r(array_values($str));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement