I have a phone number, including area code. Is there a PHP or python-accessible API or library that will return its corresponding state?
e.g. 415 -> CA. 212 -> NY.
I have a phone number, including area code. Is there a PHP or python-accessible API or library that will return its corresponding state?
e.g. 415 -> CA. 212 -> NY.
As a non-American I used Google to look it up:
The easiest way would be to store the values in a database and just query it. ALternatively, you could have an array/list/... with the area codes in it and just use the languages features to retrieve the values needed.
http://www.50states.com/areacodes/
I suggest putting everything in an array in a seperate file:
// area_codes.php
$area_codes['205'] = 'AL';
$area_codes['251'] = 'AL';
$area_codes['256'] = 'AL';
$area_codes['334'] = 'AL';
$area_codes['907'] = 'AK';
// etc.
If you need the area code, just include the file and use it like this:
include('area_codes.php');
$area_code = '205';
echo $area_codes[$area_code]; // Output: 'AL'