note 16279 added to function.explode
| From: | tmcnulty at xorsis dot com | Date: | Tue, 23 Oct 2001 15:23:37 +0000 |
| Subject: | note 16279 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19327@lists.php.net to get a copy of this message | ||
Here is yet-another-CVS-string-parser (it is actually an optimized version of an anonymous post
above, without HTML escape support)
function csvsplit($splitter,$data) {
$quotechar = '"';
$escapechar = "\\";
$instring = false;
$location = 0;
$len = strlen($data);
$field = "";
$output = array();
while ($location < $len) {
$lastchar = $char;
$char = substr($data,$location,1);
$location++;
if ($char == $quotechar && $lastchar != $escapechar)
$instring = !($instring);
if (($char == $splitter) && (!$instring)) {
$output[] = $field;
$field = "";
} else {
$field .= $char;
}
}
$output[] = $field;
return $output;
}
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+16279
http://master.php.net/manage/user-notes.php?action=delete+16279
http://master.php.net/manage/user-notes.php?action=reject+16279