Search box with preg_match

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jeaux
Forum Commoner
Posts: 25
Joined: Sun Aug 24, 2008 5:11 pm

Search box with preg_match

Post by jeaux »

If I'm doing a recipe site with a MySQL DB is preg_match the way to go? The table will be setup with recipe_id, recipe_name, recipe_description, and recipe_location. Every search I run on a search box only yields people talking about using a Google API.

Many thanks,
Joe
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Search box with preg_match

Post by GeertDD »

PHP's preg_match() does not really seem like an option to me. You would have to fetch all the records first, then loop through them all and use preg_match() to determine a match or not. An inefficient process.

Instead you can do the regex at the SQL level. MySQL has a REGEXP filter.
jeaux
Forum Commoner
Posts: 25
Joined: Sun Aug 24, 2008 5:11 pm

Re: Search box with preg_match

Post by jeaux »

Thank you so much. I needed an investigative lead. Efficiency is my goal but as a noob some ideas just seem unattainable.
Post Reply