fr34k Posted April 19, 2009 Share Posted April 19, 2009 I'm hoping someone will share a way to parse a street address into its individual parts. For instance, you'd input a string like '123 Fake St, Nowhere, ST 31337' and it would return something like... array('streetNumber' => '123', 'streetName' => 'Fake St', 'city'=> 'Nowhere', 'state' => 'ST', 'zipCode' => '31337') The more fault tolerant and adaptable to variations of address formats, the better. Anyone know of anything like that? Quote Link to comment https://forums.phpfreaks.com/topic/154707-parse-a-us-street-address-into-its-individual-parts/ Share on other sites More sharing options...
ToonMariner Posted April 19, 2009 Share Posted April 19, 2009 without writing the code for you you will need perform such operations on the string as: explode(), preg_match(), list() and that kind of thing... Quote Link to comment https://forums.phpfreaks.com/topic/154707-parse-a-us-street-address-into-its-individual-parts/#findComment-813547 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 trying to parse an address string without a database to validate whether the street names, cities, states, zip codes, etc.. exist, is a waste of time. Formats are arbitrary. So unless you have access to google map database sort of thing, don't bother. Even google maps, with all that info at their disposal, still has to give you a list of suggestions of what they think you mean. Instead, make the user enter that stuff in separate fields and validate it on more reasonably known things, like you know a zipcode is 5 numbers, you can reasonably keep a list of states and abbreviations, etc... Quote Link to comment https://forums.phpfreaks.com/topic/154707-parse-a-us-street-address-into-its-individual-parts/#findComment-813551 Share on other sites More sharing options...
fr34k Posted April 19, 2009 Author Share Posted April 19, 2009 trying to parse an address string without a database to validate whether the street names, cities, states, zip codes, etc.. exist, is a waste of time. Formats are arbitrary. So unless you have access to google map database sort of thing, don't bother. Even google maps, with all that info at their disposal, still has to give you a list of suggestions of what they think you mean. Instead, make the user enter that stuff in separate fields and validate it on more reasonably known things, like you know a zipcode is 5 numbers, you can reasonably keep a list of states and abbreviations, etc... I do have a database of addresses, but they're all broken up by street numbers, street names, cities, states, and zip codes. Ideally, I'll have the user enter the address in a single text box. This is approach is primarily due to layout restrictions and convenience for the user. I need to be able to take what's entered in there and match it against what's in the database. It is a simple concept, but seems like a complicated procedure. I was hoping that someone knew of something already available, before I went and spent the time re-inventing the wheel. Quote Link to comment https://forums.phpfreaks.com/topic/154707-parse-a-us-street-address-into-its-individual-parts/#findComment-814096 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.