shoeshine Posted September 24, 2009 Share Posted September 24, 2009 I hope someone here can help me soon with my issue What I am trying to achieve here this: I have an ajax form that has 3 dropdown menus on it representing a telephone number search. dropdown 1 has values of 800, 877, 866, 8** (8** means any of the 866, 877,800 number) dropdown 2 is for the prefix of the number and can allow numbers and a * ie: 55* 5** *** dropdown 3 is for the suffix of the number and it's identical to dropdown 2, for the exception it will allow 4 numbers or * in the box. Now when the ajax call goes out, it reads the the text file of numbers which are formatted as 8001234567 (no dashes) and I am storing those numbers into an array as $arg[] So what I am asking is what would be the preg_match_all code to find these numbers being search for? Thanks so much for your assistance! Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted September 24, 2009 Share Posted September 24, 2009 At least give it a try, the patterns should be pretty straight forward. There is a great tutorial on this site even that should help you out http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax Quote Link to comment Share on other sites More sharing options...
shoeshine Posted September 24, 2009 Author Share Posted September 24, 2009 At least give it a try, the patterns should be pretty straight forward. There is a great tutorial on this site even that should help you out http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax 3 hours later from reading this link a dozen time and I am still banging my head over this..I do not know anymore than what I did when I started... Sorry. It just doesn't make sense. Does anyone have some type of a working example I can go off of? Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted September 24, 2009 Share Posted September 24, 2009 Yeah, regex is a tough one to wrap your head around... there are preg_match_all examples on php.net (http://us2.php.net/preg_match_all) Quote Link to comment Share on other sites More sharing options...
thebadbad Posted September 25, 2009 Share Posted September 25, 2009 Here's a way to do it: <?php $file = '1234567890 8005511234 7012344232 8995551934'; $search = '8**' . '55*' . '1*34'; //replace wildcards with regex equivalent $search = str_replace('*', '[0-9]', $search); preg_match_all("~^$search$~m", $file, $matches); echo '<pre>' . print_r($matches[0], true) . '</pre>'; ?> Output: Array ( [0] => 8005511234 [1] => 8995551934 ) Quote Link to comment Share on other sites More sharing options...
shoeshine Posted September 25, 2009 Author Share Posted September 25, 2009 Here's a way to do it: <?php $file = '1234567890 8005511234 7012344232 8995551934'; $search = '8**' . '55*' . '1*34'; //replace wildcards with regex equivalent $search = str_replace('*', '[0-9]', $search); preg_match_all("~^$search$~m", $file, $matches); echo '<pre>' . print_r($matches[0], true) . '</pre>'; ?> Output: Array ( [0] => 8005511234 [1] => 8995551934 ) Thank you so much! You helped me out greatly. So much is appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.