Extract zipcodes from string and build a select statement in php -
I have a string that I capture with my DB that contains city and pincode information. I want to remove the zipcode (always 5 digits) from it and want to create an alternative statement (using PHP) as follows:
Please note that the string can have many towns, zododes, so that the solution is flexible enough to adjust it.
Try it out:
The above code exits everything except numbers and commas, then it explodes with commas, which gives you the necessary zipcode. Then loop through the zodiac array and select.
Code> & lt ;? Php $ townZip = 'Boston (02108, 02112, 02116), Chelsea (02150), Rev. (02151)'; $ Zips = Explosion (',', preg_replace ('# [^ A-Za-z, 0-9 () #', '', $ Town zip)); Echo '& lt; Select & gt; ' Echo '& lt; Option value = "" & gt; Please select & lt; / Option & gt; '; $ Prev = ''; Foreach ($ zip $ zip) {$ temp = explode ('(', $ zip); if (isset ($ temp [1]) $ {$ Prev = $ temp [0]; $ temp [0] = $ Temp [1];} echo '' & lt; option value = "'. $ Temp [0]." & Gt;'. $ Prev ''. $ Temp [0]. '& Lt; / options & gt; ; ';} Echo
Comments
Post a Comment