[英]Can't find/access tags in xml object
How to acces geo:lat
and geo:long
in this feed? 如何在此供稿中访问geo:lat
和geo:long
? Can't see it in the var_dump. 在var_dump中看不到它。
Basically I know how to use the obj returned by simplexml_load_file
, however I can't find the geo tags. 基本上,我知道如何使用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);
}
EDIT: updated code 编辑:更新的代码
I made this simple test: 我做了一个简单的测试:
<?php
$feed = simplexml_load_file('http://feeds.livep2000.nl');
echo "<pre>".print_r($feed,true)."</pre>";
?>
The reason why it doesn't show de geo tags it's because they don't exist in the $feed var. 它不显示地理标记的原因是因为它们在$ feed变量中不存在。
Sample output fo the code: 代码示例输出:
[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
)
Now you can access the Lat and Long values in this way: 现在,您可以通过以下方式访问纬度和经度值:
$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>";
}
And the proper output of the script: 以及脚本的正确输出:
Lat: 52.5123727 | Long: 4.9528409
Lat: 51.52939 | Long: 5.0269987
Lat: 52.4189359 | Long: 4.8860944
Lat: 52.5146807 | Long: 4.7027031
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.