Re: Parsing a phrase

From: Date: Sun, 12 Dec 2010 19:51:05 +0000
Subject: Re: Parsing a phrase
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-309993@lists.php.net to get a copy of this message
Rick Dwyer wrote:
Hello all. I have a page where the user can enter a search phrase and upon submitting, the search phrase is queried in MySQL. However, I need to modify is so each word in the phrase is searched for... not just the exact phrase. So, "big blue hat" will return results like: "A big hat - blue in color" "Hat - blue, big" SQL would look like .... WHERE (item_description like "%big%" and item_description like "%blue%" and item_description like "%hat%" )
You may be better to use full text and MATCH for this, see: http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html However..
So, via PHP, what is the best way to extract each word from the search phrase to it's own variable so I can place them dynamically into the SQL statement.
There are many ways you can do this: http://php.net/explode http://php.net/str_split http://php.net/preg_split Many examples can be found on the above pages, and you're real solution depends on how many edge-cases you want to cover, but the above will cover most approaches :) Best, Nathan

« previous php.general (#309993) next »