If you're splitting them up with preg_split(), you can combine them with
implode(). Something like

$foo = ".*" . implode(".*", $words);

Or don't use an array at all. Just replace anything that's not a valid
search character...

$regex = preg_replace("/[^A-Za-z]/", ".*", $search);

J


Kelvin Poon wrote:

> Hi,
> 
> I am sorry if this problem is too easy but I just can't figure out a way
> to do this.
> 
> I am making a search engine and I would have the user to type a sentence
> to search for.
> 
> Let's say it is stored in $search.
> 
> My search enginue will bring up a result IF and only if ALL of the words
> in
> $search exist in the result.  For example
> if
> 
> $search = Vax Useful Commands
> 
> Then the result is only true if (eregi(".*Vax.*Useful.*Commands.*",
> 'possible result')) is true
> 
> Now, I don't know how many words there are in $search initially.  How do I
> do a search like that?  I mean if I know $search is 3 words then I can do
> 
> $words = preg_split("/  /", $search);
> 
> if (eregi(".*words[0].*words[1].*words[2].*", 'possible result')) {
>  .....
> }
> 
> 
> Even if I know how many words there are, everytime the number of words in
> $search can be different.
> 
> Can anybody give me any ideas?
> Thanks a lot
> 
> Kelvin


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

Reply via email to