Page 1 of 1

[SOLVED] Search

Posted: Sun Oct 16, 2005 5:50 am
by AndrewBacca
I'm tring to make a search engine for one of my projects.

I have it breaking the search string up into pieces and searching for all the words seperatly. but I want to allow the user to "enclose their search" in "" and it will search for that phrase?

but so far it has not hit me how to do this

so any help will be very usefull thanx

Andrew

Posted: Sun Oct 16, 2005 5:51 am
by s.dot
Sounds like you'll need a regular expression to extract values between quotes.

Posted: Sun Oct 16, 2005 5:54 am
by AndrewBacca
anyideas?! :)

Posted: Sun Oct 16, 2005 5:59 am
by s.dot
hmm.. something like

Code: Select all

$searchquery = $_POST['search'];

preg_match("#\"(.+?)\"#", $searchquery, $matches);

foreach($matches[0] AS $search)
{
    mysql_query("SELECT * FROM table WHERE field LIKE '%$search%'");
}
I'm not too sure though, my regular expression experience isn't too great. =/

Posted: Sun Oct 16, 2005 6:14 am
by AndrewBacca
[SOLVED]

got it thx for the help :)