willpower Posted February 16, 2007 Share Posted February 16, 2007 Hi Im dealing with UK postcodes I need to check the first to chars in a $string against vars contained in an array. ie $postcode= "M23 4EF" $Array_to Check = ('SW','NW','SF') Not sure what is the best way to do this... Just need to check if 1st chars in $postcode contain any of $Array_to_check and return tru/false/ Thanks Will Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 <?php function makeRegEX(&$item, $key) { $item = '/^' . $item . '/'; } $postcode= "M23 4EF" $arr = ('SW','NW','SF'); array_walk($arr, 'makeRegEx'); if (preg_match($arr,$postcode)) { echo "Found"; } Quote Link to comment Share on other sites More sharing options...
willpower Posted February 16, 2007 Author Share Posted February 16, 2007 top one matey...thanks 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.