RES: [PHP] help with explode()
| From: | Jônatas Zechim | Date: | Fri, 24 Apr 2009 15:55:54 +0000 |
| Subject: | RES: [PHP] help with explode() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-291945@lists.php.net to get a copy of this message | ||
$var = "John \"Jill\" \"Judy Smith\"";
echo $var;
$var2=explode("\"",$var);
echo '<pre>';
print_r($var2);
echo '</pre>';
$tVar=count($var2);
for($i=0;$i<$tVar;$i++){if(strlen($var2[$i])<2){unset($var2[$i]);}else{$var2
[$i]=trim($var2[$i]);}}
$var2=array_values($var2);
echo '<pre>';
print_r($var2);
echo '</pre>';
Is that u want?
Zechim
SP/Brazil
-----Mensagem original-----
De: Adam Williams [mailto:awilliam@mdah.state.ms.us]
Enviada em: sexta-feira, 24 de abril de 2009 12:41
Para: PHP General list
Assunto: [PHP] help with explode()
I have a form where users submit search terms and it explodes the terms
into an array based upon spaces. But, how can I have explode() keep
words in quotation marks together? For example, if someone enters on
the form:
John Jill "Judy Smith"
and I run $termsarray = explode(" ", $_POST["terms"]);
it explodes into:
Array ( [0] => John [1] => Jill [2] => "Judy [3] => Smith" )
but I'd like it to explode into:
Array ( [0] => John [1] => Jill [2] => "Judy Smith" )
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php