Php 如何检索特定的XML标记名?
上面的提要返回一个XML文档。我可以使用这些代码成功地检索标签名,如标题、说明和链接Php 如何检索特定的XML标记名?,php,xml,Php,Xml,上面的提要返回一个XML文档。我可以使用这些代码成功地检索标签名,如标题、说明和链接 $xml = file_get_contents($feed_url); $xml = trim($xml); $xmlObject = new SimpleXmlElement($xml); foreach ($xmlObject->channel->item as $item) { $title = strip_tags($item->
$xml = file_get_contents($feed_url);
$xml = trim($xml);
$xmlObject = new SimpleXmlElement($xml);
foreach ($xmlObject->channel->item as $item) {
$title = strip_tags($item->title);
$description = strip_tags($item->description);
}
我怎样才能得到它
您看到的是另一个XML名称空间。您可以使用花括号访问它:
$a10 = $item->{'a10:updated'}
这里我们使用DOMDocument从标记中提取数据
输出:
2017-05-07T09:14:00+03:00希望我的帖子能帮到你。。。
$a10 = $item->{'a10:updated'}
<?php
ini_set('display_errors', 1);
$xml='<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>title</title>
<link>link</link>
<description>news</description>
<item>
<guid isPermaLink="true">link</guid>
<link>link</link>
<title>Tiele</title>
<description>Descr</description>
<enclosure url="image" type="image/jpeg"/>
<a10:updated>2017-05-07T09:14:00+03:00</a10:updated>
</item>
</channel>
</rss>';
$xmlObject = new DOMDocument();
$xmlObject->loadXML($xml);
$result=$xmlObject->getElementsByTagNameNS("http://www.w3.org/2005/Atom", "*");
print_r($result->item(0)->textContent);