note 37725 added to function.explode
| From: | francisco at sirius dot com dot co | Date: | Mon, 24 Nov 2003 17:04:07 +0000 |
| Subject: | note 37725 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60916@lists.php.net to get a copy of this message | ||
Here I have some aditions to the code provided by hhromic at udec dot cl (When having empty chains)
function csv_explode ($str, $delim=',', $qual="\"")
{
// Largo de la línea
$largo=strlen($str);
$dentro=false;
$palabra="";
for ( $i=0; $i<$largo; $i++)
{
if ( $str[$i] == $delim && !$dentro )
{
$salida[] = $palabra;
$palabra="";
}
else if ( $str[$i] == $qual && ( $i<$largo && $str[$i+1] == $qual ) )
{
if ($str[$i+2] == $delim) {//empty
$palabra .= "";
}
else $palabra .= $qual;
$i++;
}
else if ( $str[$i] == $qual )
{
$dentro = !$dentro;
}
else
{
$palabra .= $str[$i];
}
}
$salida[]=$palabra;
return $salida;
}
Cheers from Colombia
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37725
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37725&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37725&report=yes
Search -- http://master.php.net/manage/user-notes.php