Using Geonames from PHP
Really simple example on how to use Geonames.org web service from PHP.
Here we will retrieve all the countries from an XML and print it as a combo:
$xmlcountries = 'http://ws.geonames.org/countryInfo'; echo '<select>'; $countries = simplexml_load_file($xmlcountries); foreach ($countries->country as $country) { echo '<option value="' .$country->geonameId.'">'.$country->countryName.'</option>'; } echo '</select>';
Combo choosing children nodes:
$xml = 'http://ws.geonames.org/children?geonameId='.$gid.'&lang='.$lang; echo 'Xml <a href="'.$xml.'">'.$xml.'</a><br />'; echo '<select>'; $elements = simplexml_load_file($xml); foreach ($elements->geoname as $e) { echo '<option value="' .$e->geonameId.'">'.$e->name.'</option>'; } echo '</select>';
Combo to select the language:
$a_lang=array("EN", "DE", "FR", "ES", "JA", "ZH", "RU", "HE", "SV", "BG", "PT", "FI", "KO");//array of current languages echo '<select>'; foreach ($a_lang as $l) { echo '<option value="' .$l.'">'.$l.'</option>'; } echo '</select>';
I used combos, but can be any other thing, in my case I’ll use more checkboxes.
In this demo,you have all from before and once you select it would be appearing child nodes (states,provinces,cities,neighborhoods…. )
See the demo | Dowload the demo
- Error reporting for PHP
- phpSEO - Class for better SEO in PHP
- Prevent code injection in PHP - Updated
- Count Words Repetitions in PHP
- Prevent spam in your PHP site with akismet
Help sharing and Flatter me ;)
