PDA

View Full Version : Directory Search...?



cyandi_man
January 25th, 2009, 09:57 AM
Hi guys - i have a mini search page on my site in which i want people to be able to pull contact info by either typing in a Phone number or Company name in the search fields. Question is:

1. how do i have php compare the Phone number entered and phone number on database by just verifying that they have the same numbers in the same sequence? (ignoring any brackets or dashes)

2. how do i have the Company Name field search the database for any word that was entered in the input field excluding "the"

Please advise ...thanks fellas!

simplistik
January 26th, 2009, 10:03 AM
1. You'll want to strip everything that's not a number from the values you're comparing, that's easy you can do that by doing:


$str = preg_replace("/[^0-9]/", "", $str);


2. Similarly when you're doing the search you'd do something like


$str = str_replace(" the ", " ",$str);

which strips the word 'the' using space before and after it to determine whether or not it's a word or part of another word, and converts it to a single space