note 57817 added to function.explode

From: Date: Sat, 15 Oct 2005 00:51:38 +0000
Subject: note 57817 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-97043@lists.php.net to get a copy of this message
Re: My Last Post I left an important part of my last post out. My previous explode_quote method will leave the encapsulation characters in the resulting arrays. The time average on 4 executions for this modification is 68.66882109642. (On explode() it's 3 seconds, which has almost made me want to write a module for things like this, so they can be binary-compiled. Anyway, here's the code to leave out encapsulation characters: <?php function explode_quote($ADelim, $AString, $AEncap = '"') { $retval = array(); //if we have an empty string, don't even bother processing if (empty($AString)) return $retval; //calculate source length and initialize some variables $srcLength = strlen($AString); $insideEncap = false; //0..X string indexing in PHP, we'll be reading +1 $lastPos = -1; for ($x=0;$x<$srcLength;$x++) { if ($AString[$x]==$AEncap) { if (!($insideEncap = !$insideEncap)) { $retval[] = substr($AString, $lastPos+2, $x-$lastPos-2); $lastPos = ++$x; } } elseif (!$insideEncap && $AString[$x]==$ADelim) { $retval[] = substr($AString, $lastPos+1, $x-$lastPos-1); $lastPos = $x; } } //if string doesn't end with delimiter, then throw remaining data to result if ($lastPos!=$srcLength) $retval[] = substr($AString, $lastPos+1, $srcLength); return $retval; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57817 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57817&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57817&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97043) next »