note 16279 deleted from function.explode by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 21:25:32 +0000 |
| Subject: | note 16279 deleted from function.explode by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22013@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;
}