note 32081 deleted from function.explode by aidan
| From: | aidan@php.net | Date: | Thu, 01 Jul 2004 09:55:14 +0000 |
| Subject: | note 32081 deleted from function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72251@lists.php.net to get a copy of this message | ||
Note Submitter: scorp1us@hotmail.com
----
I had problems with the above function returning empties when there shouldn't be. Here's
my take. I hope some of you find this of value.
<?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];
}
}
return $out;
}
?>