开发者

PHP script to parse address?

开发者 https://www.devze.com 2023-02-27 01:38 出处:网络
I am looking for a PHP script to parse through a name and address field, the kind that people attach to the end of their emails.It would be uploaded as plain text and would be in this format:

I am looking for a PHP script to parse through a name and address field, the kind that people attach to the end of their emails. It would be uploaded as plain text and would be in this format:

John Q. Public
Director of Some Thing
123 Elm Street 
Anytown, ST 11001
(000) 555-1212
(000) 555-1213 FAX
开发者_如何学C

The addresses tend to vary in format, which is why I am wondering if anyone has taken this on yet. Thanks.


Because addresses can vary so much, this is not a trivial parsing task. If possible, I would recommend using a proven service such as The Google Geocoding API.

You could use PHP's file_get_contents() to retrieve the answer and json_decode() to read it (JSON is one of several formats the Geocoding API can return).


SmartyStreets offers an extraction tool to do this sort of thing. You can paste in any block of text and it will scrape through to extract any addresses that might be in it. SmartyStreets specializes in address validation, so our developers have already sorted out the parsing problem. You can check it out here. The extractor is a web tool, but you can use it programmatically using PHP. It does require at least a free subscription.

Here's a look at what it found from your fake email signature above:

PHP script to parse address?

(Just to be clear, I do work at SmartyStreets.)


Google Geocoding has a limit of 2,500 per day.

If you have alot of data being parsed, I suggest using another services.

The cheapest geocoding api that can return a formatted address similar to Google would be Geocode Farm. They have jSON also, so you can still use file_get_contents with json_decode(). I would suggest you use their 25,000/day ($25/mo) and parse it out through that if you have alot of data. If more than that, upgrade to a different plan. If you only need 2,500 but more in the future, I suggest you still use them because they are free for 2,500 too and you can upgrade the plan instantly to paid one in their dashboard.

  • Kind of biased towards using GeocodeFarm because their service is the only one that I have found that is better than Google, dirt cheap, and returns close to the same results if not spot on most times. Never had downtime and love them. I use GeocodeFarm for all my geocoding and address parsing.

The down site: They don't provide the address components as Google does, only the returned / corrected address... :/ Hopefully they add address components in the future. The only thing I've found that's missing. :(

P.S. Either Google them or I linked their site to the word "Geocode Farm" above...

P.S.S. Sorry for late reply, but hopefully this will help someone else who looks for this...

0

精彩评论

暂无评论...
验证码 换一张
取 消