Jump to content

Parse a US street address into its individual parts?


fr34k

Recommended Posts

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.