function geonames_populations ($countries
{
$data = file_get_contents"http://www.geonames.org/countryInfo?");
if ($data==false) {
throw new Exception"Data was not returned by geonames.org");
} else {
// parse the XML
$obj = simplexml_load_string$data);
// put countries in lower case
for ($ii=0;$iicount$countries); $ii++) {
$countries$ii]=strtolower$countries$ii]);
}
// get the population data for the matching countries
$all_countries = $obj->country;
$valuesarray();
foreach ($all_countries as $country) {
if (array_searchstrtolower$country->countryName), $countries)!==false) {
$country_name = $country->countryName.'';
$country_pop = $country->population+0;
$values$country_name] = $country_pop
}
}
return $values
}
}