note 13669 deleted from function.explode by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 21:24:24 +0000 |
| Subject: | note 13669 deleted from function.explode by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22006@lists.php.net to get a copy of this message | ||
/**
* NAME: explodeQuoted()
* DESCRIPTION: Explode a quoted string into elements. Does not work
* flawlessly because it only checks the first and last char
* of every word. But this will suffice normally and is very fast.
* AUTHOR: Marc Spoorendonk a.k.a. Grmbl
* DATE: 2001-06-28 10:31:52 CET
*/
function explodeQuoted($str)
{
$inQuotes=false;
$words=explode(" ", $str);
foreach($words as $word) {
if($inQuotes==true) {
// add word to the last element
$elements[sizeof($elements)-1].=" ".$word;
if($word[strlen($word)-1]=="\"") $inQuotes=false;
}
else {
// create a new element
$elements[]=$word;
if($word[0]=="\"" && $word[strlen($word)-1]!="\"")
$inQuotes=true;
}
}
return $elements;
}