Skip to content

Instantly share code, notes, and snippets.

@daynebatten
Created March 13, 2015 17:55
Show Gist options
  • Select an option

  • Save daynebatten/22e28c734887992988fa to your computer and use it in GitHub Desktop.

Select an option

Save daynebatten/22e28c734887992988fa to your computer and use it in GitHub Desktop.
<?php
/* HTML Query String Parameters */
$options = array
(
'street' => '1600 Pennsylvania Avenue Northwest',
'city' => 'Washington',
'state' => 'DC',
'zip' => '20500',
'benchmark' => 'Public_AR_Current',
'format' => 'json'
);
/* Build a URL */
$url = 'http://geocoding.geo.census.gov/geocoder/locations/address?'.http_build_query($options);
/* Run query using cURL */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
/* Decode the JSON response, and print it out */
print_r(json_decode($result, true));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment