Re: Re: Parsing a phrase

From: Date: Sun, 12 Dec 2010 20:50:49 +0000
Subject: Re: Re: Parsing a phrase
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-309994@lists.php.net to get a copy of this message
Thanks Nathan. The MySQL Match/Against will probably work well... but I would need to somehow add a "+" to the beginning of each word in the phrase so PHP will still be involved. --Rick On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:
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 --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#309994) next »