Hi everyone,
I'm simply trying to grab a simple element from an XML.
The XML has the following format:
<geonames>
<geoname>
<toponymName>Grand Tikal Futura Hotel</toponymName>
<name>Grand Tikal Futura Hotel</name>
<lat>14.618</lat>
<lng>-90.5249</lng>
<geonameId>6475052</geonameId>
<countryCode>GT</countryCode>
<countryName>Guatemala</countryName>
<fcl>S</fcl>
<fcode>HTL</fcode>
<distance>1.23124</distance>
</geoname>
</geonames>
My PHP is currently like this (note the link to the XML is calling two PHP variables as part of it's URL)
<?PHP
header('Content-Type: text/plain');
$userId = '-495015601289433027';
if ( $_GET['user'] ) {
if ( is_numeric( $_GET['user'] ) )
$userId = $_GET['user'];
else
exit('This isn\'t a valid user id.');
}
$url = 'http://www.google.com/latitude/apps/badge/api?user='.$userId.'&type=json';
// We get the content
$content = file_get_contents( $url );
// We convert the JSON to an object
$json = json_decode( $content );
$coord = $json->features[0]->geometry->coordinates;
$timeStamp = $json->features[0]->properties->timeStamp;
if ( ! $coord )
exit('This user doesn\'t exist.');
$date = date( 'Y-m-d H:i', $timeStamp );
$lat = $coord[1];
$lon = $coord[0];
$sXML = new SimpleXMLElement('http://api.geonames.org/findNearby?lat=$lat&lng=$lon&username=klous&style=short', NULL, TRUE);
print_r ($sXML);
?>
But with this I get an error:
[message] => error parsing parameter
[value] => 14
I've been trying and searching all morning, lots of different ideas, but with no luck. At the moment, for simplicity, I'm simply trying to output the needed field "GeonameId". I would really appreciate some help, and apologies.... I am, quite obviously, a novice! Thanks!