PHP script to parse address? - php

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

Related

How does one go about incorporating location based services into a social network?

I am currently working on a special interest social network. The part that I'm having trouble with is the location of individual users.
My ideal solution would be a system where users enter their city/state and/or zip code, and could search for other users within their own area.
What I think separates my question from many existing threads is my needs and my resources. I don't have much capital at all to invest in a paid database, nor do i need all the features offered by the ones i've come across. I'm really looking for suggestions in which direction I need to go in. I've seen a lot of threads with similar ideas, but none that give the type of answers i need for my project. I'm not sure where to start with this, so any help would be greatly appreciated!!
Also, I'm building my application in php5.
these barebones hosting packages include MySQL... 1and1.com
so you could store the locations, and use the Haversine formula to find nearby users: http://code.google.com/apis/maps/articles/phpsqlsearch.html#findnearsql
For getting the data in Lat/Lng format, you could consider using navigator.geolocation...it's fairly well supported, but you could do a test for it: if(navigator.geolocation) and if it's NOT, provide a text field for city/state or ZIP, and then geocode that to get to Lat/Lng (google has a service here: http://code.google.com/apis/maps/documentation/geocoding/ ) but it does have some limitations, like 2500 queries/day unless you pay for an upgraded license
Actually, even if the navigator approach is available, you might want to provide a confirmation step (in case their ISP is returning an different location)...like "you appear to be HERE, is this accurate, or would you like to supply your own location"
Thank you Robot Woods, Your answer inspired some creative googling that lead me to the answer to my problem. Yahoo offers PlaceFinder! http://developer.yahoo.com/geo/placefinder/
PlaceFinder can be used to get a Latitude/Longitude from a user inputted city/state combination or a zip code. And best of all... Its Free!!! Fits my budget perfectly!

How to make a PHP based script for finding UK addresses by entering postcode?

I've almost looked everywhere but nothing found, so my only hope would be here though! :(
I want to make a PHP based script for finding UK address by entering postcode, so a list would show with a number of houses' numbers!
Any idea how I could do that, I know that I must use API, even though I search for Google Maps API for this, but nothing found whatsoever!
Any idea?
I need this particular script for an additional registration script which allows uk residents to be able to register for a specific reason, so please help if you know where I could get started!
Thanks in advance! :)
Generally these systems utilise the Royal Mail PAF database, but this does cost quite a lot of money.
There are services out there that offer X amount of requests for a set price (or a monthly price), so if buying the full thing isn't an option then you could have a look into one of those services.
It is something you are going to need to spend money on though - it's not a service that anyone (that I've ever found) is offering for free.
I don't think this is something you can get out of Google maps either.
Well, there are quite a few projects working on this dataset - just look at e.g. http://www.freethepostcode.org/ and the associated projects.
You can fetch the postcode latitude and longitude using google api:
http://maps.googleapis.com/maps/api/geocode/json?address=(POSTCODE HERE)&sensor=false
then using the lat and long from that you can get the street name
http://maps.googleapis.com/maps/api/geocode/json?latlng=(LAT),(LNG)&sensor=false
see reference here:
http://code.google.com/apis/maps/documentation/geocoding/
We can get all UK addresses by postal code with api.getaddress.io API. You can found an example on https://usingphp.com/post/how-to-get-all-uk-addresses-by-postal-code

How do I validate country and state/province names and postal codes?

I am building an web app (with PHP) that requires users to subscribe. I would like for them to identify where they are from. So what is the best way to validate there country/state(or province)/city/postal code? Is there a DB with all the information? Which one is the best?
There are many options for address validation. The main issue is how much traffic your website will receive and whether or not you need support. If you are relatively small, you can get away with the free services like the following:
Google Maps API (example) (you may be breaking the TOS)
UPS Address Verification API (example)
USPS Address Web Tools
If you need something more robust or customizable, it will probably be necessary to pay for a service.
I know this is old, but to prevent others from going down the wrong path, the chosen answer to use Google API's may not have been aware of the google terms of service license (...the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.)
If you're not using a map...
and your requirements do not require commercial grade data, this sums up some options and what to look for.
however, if you need commercial data, greatdata.com and melissadata.com both sell real commercial level data products.
This thread is also helpful: stackoverflow thread on zip code data
Use the Google Geocoding API They allow 2,500 requests per day and you can pay for more. It will take an address and give you very detailed information on it and provide validation if you code it into your application.
Use the USPS Address Information API.
I've utilized data that can be purchased inexpensively from http://zipcodedownload.com/ to provide zip code validation/address correction in our applications.

php script for sms facility

I'm making a project in my college, and I am making a web application. This web application is in openSuse. So the OS is Linux and I'm writing the code in php.
Now I want scripts in php for including sms facility in my project. So I need full information how to go about it and what code to implement
You need to use an online SMS provider. A quick trip to google brought up this: http://www.messagemedia.co.uk/sms-gateways.html (UK only, search in your country to find one that'll work for you). Then go to their API page and they should give you a nice PHP API to use.
Two basic approaches
Use an online SMS provider, as suggested by many other comments
Use a GSM modem with software like Gammu to handle sending and receiving text messages; almost any USB GSM dongle can handle this.
If I were to do something like this, I would just use the mail() function of PHP.
In the US at least, I think all phone numbers have an email address:
19999999999#sub.carrier.com
If you can extract the carrier from the number, you could just strip all non-numeric characters from the number and use the PHP mail function to send an email to that address, which in turn is a text message. This is how I forward emails via text to my feature phone (funny, the name is misleading).
There are a number of sites that extract information from the number, but I couldn't find an explicit algorithm. Here's one (I bet you could just use file_get_contents() on that webpage to get the carrier): http://fonefinder.net/
It's not too complicated, so have fun!
Have you seen http://www.twilio.com?
It's really cheap and incredibly easy to use. Why reinvent the wheel? :)
Depends on your needs. If you need to send AND receive and be able to process the incoming messages you are going to need more than just a simple SMS provider and are going to need somebody to partition a short/long code (I'm assuming you don't want to spend 1000$/month on a Short Code) to process incoming messages and forward them to you. You can set up keywords, or regular expressions that get run on messages then forwarded to your server.
If you are just going to be using just outbound SMS (notifications, etc.) than you can use something simple like Clickatell or Twilio.

What is the best approach to geo targeting?

Lately geo-targeting has been pretty popular in technology. By IP, cell tower, GPS, using browser plugins, HTML5?, mobile devices ...
Since I'm about to add some geo-targeted features on our site, I wanted to know what's the best approach. Is there some API that uses a mix of all those technologies? Or at least, what API/service would you recommend I use?
The service I'm working on doesn't need to be 100% accurate, so I'm OK with geo-IP, but if there's an easy way to do better, why not.
Technologies used are php, javascript, ajax, java.
Whatever you do please please please don't set the language of your website based on the user's IP, and then make it almost impossible to change unless you know said language and you feel like wasting hours (like ebay and paypal, among others, do). Use the browser's language.
Not everyone in, let's say, France speaks or wants to speak French.
I guess it's not very related to your question but i felt the need to rant about this, sorry :)
GEO IP is probably the best approach for now.
HTML5 looks promising, but it'll be a while before it's widely supported. And even then it requires explicit user approval, which kind of limits the possibilities for using it (for example auto-redirecting to a country specific version of a website)
For a start try the free http://api.hostip.info?ip=x.x.x.x (www.hostip.info for website)
It'll give you city and country in a xml structur. I've a small proxy-script writen in PHP on the http-server, which a html page calls with ajax and show the infomation in text and on a Google map using the Google geocoding api. Later on you can easy replace the api.hostip.info with an other api.
I would use IP address detection by default, and then optionally ask for a more specific location using the Javascript/HTML5 navigator.geolocation API when present. (For example, in iPhone Safari)
Most users are still using devices that don't know the location themselves, so plugins that are available will not get a better location than IP address detection does anyway. (Alternatively, they'll prompt users to manually enter data, which is annoying)
Max Mind is good. But if you are looking for a free solution, you may want to consider using the javascript geocoder. Eventually they will support addresses and country, but right now, they only give you a latitude and longitude.

Categories