如何在此Feed中访问geo:lat
和geo:long
?无法在var_dump中看到它。
基本上我知道如何使用simplexml_load_file
返回的obj,但我找不到地理标记。
$feed = simplexml_load_file('http://feeds.livep2000.nl/');
//var_dump($feed);
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$description = (string) $item->description;
$pubDate = (string) $item->pubDate;
$geo = (string) $item->geo:lat;
print_r($item);
}
编辑:更新的代码
答案 0 :(得分:0)
我做了这个简单的测试:
<?php
$feed = simplexml_load_file('http://feeds.livep2000.nl');
echo "<pre>".print_r($feed,true)."</pre>";
?>
它没有显示de geo标签的原因是因为它们不存在于$ feed var中。
代码的示例输出:
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => SimpleXMLElement Object
(
)
[link] => http://monitor.livep2000.nl?SPI=1311111908030208
[description] => SimpleXMLElement Object
(
)
[pubDate] => Mon, 11 Nov 2013 19:08:03 +0100
[guid] => 1311111908030208
)
[1] => SimpleXMLElement Object
(
[title] => SimpleXMLElement Object
(
)
[link] => http://monitor.livep2000.nl?SPI=1311111908010223
[description] => SimpleXMLElement Object
(
)
[pubDate] => Mon, 11 Nov 2013 19:08:01 +0100
[guid] => 1311111908010223
)
现在您可以通过以下方式访问Lat和Long值:
$feed = simplexml_load_file('http://feeds.livep2000.nl');
foreach ($feed->channel->item as $item) {
$ns_dc = $item->children('http://www.w3.org/2003/01/geo/wgs84_pos#');
echo "Lat: ".$ns_dc->lat." | Long: ".$ns_dc->long."</br>";
}
脚本的正确输出:
Lat: 52.5123727 | Long: 4.9528409
Lat: 51.52939 | Long: 5.0269987
Lat: 52.4189359 | Long: 4.8860944
Lat: 52.5146807 | Long: 4.7027031