note 66715 deleted from function.explode by bjori

From: Date: Mon, 25 Sep 2006 08:06:09 +0000
Subject: note 66715 deleted from function.explode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117568@lists.php.net to get a copy of this message
Note Submitter: bfpdevel at gmail dot com ---- This is a entire modification of the markus function I don't know if that function work fast with long strings, I only test it with a max of 600 characters and work very fast. This function have a minor bug, if someone know how to fix them, wellcome. at the first line, I change the cuotes for a "not very used" character. But if that character are used in the $string, them we have a problem. The line is: $op = array("\\'"=>"~", "\\\""=>"¦"); Sorry my english <?php function quote_explode( $delim, $string, $encap = '"' ) { $op = array("\\'"=>"~", "\\\""=>"¦"); foreach($op as $key => $val) $string = str_replace($key, $val, $string); $localstr = ""; $s = str_split($string); for($i=0; $i < count($s); $i++) { if($s[$i] == $encap && (!$action || $action == "close")) $action = "open"; else if($s[$i] == $encap && $action == "open") $action = "close"; if($s[$i] == $delim && !$action) { foreach($op as $key => $val) $localstr = str_replace($val, $key, $localstr); $r[] = $localstr; $localstr = ""; continue; } if($action == "open" && $s[$i] != $encap) $localstr .= $s[$i]; else if($action == "close") $action = false; else if($s[$i] != $encap) $localstr .= $s[$i]; } $r[] = $localstr; return $r; } ?>

« previous php.notes (#117568) next »