我正在使用以下PHP代码获取时区:
$url = 'http://api.geonames.org/timezone?lat=' . $latitude . '&lng=' . $longitude . '&username=demo';
$xml = simplexml_load_file($url);
foreach($xml->children() as $timezone)
{
echo "TimezoneId: ".$timezone->timezoneId." ";
echo "DstOffset : ".$timezone->dstOffset." ";
echo "GmtOffset : ".$timezone->gmtOffset." ";
}
它可以工作,但是对于南极洲的纬度和经度,例如会返回错误状态消息:
<status message="no timezone information found for lat/lng" value="15"/>
如何输出这个消息?
我正在尝试这样做:
if ($xml->status) {
echo "error: ".$timezone->status['message']. "";
}
但不起作用