note 66715 added to function.explode

From: Date: Fri, 26 May 2006 21:44:12 +0000
Subject: note 66715 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-112344@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 66.163.161.117 Probable Submitter: 200.125.48.113 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/note/edit/66715 Del: integrated -- http://master.php.net/note/delete/66715/integrated Del: useless -- http://master.php.net/note/delete/66715/useless Del: bad code -- http://master.php.net/note/delete/66715/bad+code Del: spam -- http://master.php.net/note/delete/66715/spam Del: non-english -- http://master.php.net/note/delete/66715/non-english Del: in docs -- http://master.php.net/note/delete/66715/in+docs Del: other reasons-- http://master.php.net/note/delete/66715 Reject -- http://master.php.net/note/reject/66715 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112344) next »