Re: help with explode()
| From: | Jan G.B. | Date: | Fri, 24 Apr 2009 16:34:20 +0000 |
| Subject: | Re: help with explode() | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-291948@lists.php.net to get a copy of this message | ||
2009/4/24 Adam Williams <awilliam@mdah.state.ms.us>:
>
>
> Jan G.B. wrote:
>>
>> You could try it with regular expression matching..
>> for example:
>> <?php
>> preg_match_all('/([a-z]+|"[a-z ]+")/i', $searchstring,
>> $resultarray);
>> ?>
>>
>>
>> Regards
>>
>
> Thanks. That seems to create 2 duplicate arrays, though. Can it be
> narrowed down to just array [0]?
>
> preg_match_all('/([a-z]+|"[a-z ]+")/i', $_POST["terms"],
> $termsarray);
> echo $_POST["terms"]."<br>";
> print_r($termsarray);
>
> displays:
>
> John Jill "Judy Smith"
> Array ( [0] => Array ( [0] => John [1] => Jill [2] => "Judy Smith" ) [1]
> =>
> Array ( [0] => John [1] => Jill [2] => "Judy Smith" ) )
>
Yes, preg_match_all returns all matches and the subpattern matches
(the "stuff" inside the brakes)
You can ommit stop it by using (?:) instead of ()..
So: preg_match_all('/(?:[a-z]+|"[a-z ]+")/i', $_POST["terms"],
$termsarray)
You might want to check out the regular expression manuals on
http://www.php.net/manual/en/book.pcre.php
regards
>