note 13410 deleted from function.explode by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 21:23:12 +0000 |
| Subject: | note 13410 deleted from function.explode by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22004@lists.php.net to get a copy of this message | ||
If you want to split a CSV string that looks like this:
"text; more text";text &231;;12;16;"..."
you might find this useful:
<P>
function myexplode($splitter,$data) // works like explode but checks for &231; and " ... ;
... "
{
$instring=false;
$inhtmlesc=false;
$rest=$data;
$feld="";
$ret=array();
while($rest)
{
$zeichen=substr($rest,0,1); // Aktuelles Zeichen
$rest=substr($rest,1); // Rest
if($zeichen=="\"")
{
if(!$instring) $instring=true;
else $instring=false;
}
if($zeichen=="&") $inhtmlesc=true;
if($zeichen==" ") $inhtmlesc=false;
if(($zeichen==$splitter) && (!$instring) && (!$inhtmlesc) )
{
$ret[]=$feld;
$feld="";
}
else
{
if($zeichen==";") $inhtmlesc=false;
$feld.=$zeichen;
}
}
return $ret;
}