Re: help with explode()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/4/24 Adam Williams <awilliam@xxxxxxxxxxxxxxxx>:
> 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" )
>


You could try it with regular expression matching..

for example:
<?php
    preg_match_all('/([a-z]+|"[a-z ]+")/i', $searchstring, $resultarray);
?>


Regards

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux