Skip to content

Instantly share code, notes, and snippets.

@stephenkeable-allies
Created February 20, 2015 13:46
Show Gist options
  • Save stephenkeable-allies/164acedfa55573d24f95 to your computer and use it in GitHub Desktop.
Save stephenkeable-allies/164acedfa55573d24f95 to your computer and use it in GitHub Desktop.
Basic PHP Country List Example using PostCoder Web. Find out more at - http://developers.alliescomputing.com/postcoder-web-api/geocoding/countries
<?php
// Insert your PostCoder Web API Key here
// Sign up for free at www.alliescomputing.com/postcoder/sign-up
$pcw_api_key = "YOUR-API-KEY-HERE";
// URL we are calling with API key and url encoded postcode
$pcw_country_url = "http://ws.postcoder.com/pcw/". $pcw_api_key ."/country";
// Get and JSON decode the response from the service
$response = json_decode(file_get_contents($pcw_country_url));
// Basic display HTML below, using foreach
?>
<select>
<option>Select country...</option>
<?php foreach ($response as $country) : ?>
<option value="<?= $country->iso2 ?>"><?= $country->countryname ?></option>
<?php endforeach; ?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment