note 32247 deleted from function.explode by aidan
| From: | aidan@php.net | Date: | Thu, 01 Jul 2004 09:55:09 +0000 |
| Subject: | note 32247 deleted from function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72250@lists.php.net to get a copy of this message | ||
Note Submitter: filiberto
----
Your funcion ignores the last element of the CSV string.
You have to add the line "$out[]=$word;" just befor the "return $out;". The
function now looks like:
<?php
function csv_explode2($str, $delim=',', $qual="\"")
{
$len=strlen($str);
$inside=0;
for ($i =0; $i<$len; $i++) {
if ($str[$i]==$delim && !$inside) {
$out[]=$word;
$word='';
} else if ($str[$i]==$qual) {
$inside=!$inside;
} else {
$word.=$str[$i];
}
}
$out[]=$word;
return $out;
}
?>