我有一个 XML 文档,它使用斜杠:注释。当我使用 php 尝试检索这些节点中的内容时,它只是不起作用。
这是我的代码:
<?php
$rss = new DOMDocument();
$rss->load('http://terrodactyl.netau.net/wordpress/?feed=rss2');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'commentcount' => $node->getElementsByTagName('slash:comments')->item(0)->nodeValue,
'creator' => $node->getElementsByTagName('dc:creator')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$creator = $feed[$x]['creator'];
$comments = $feed[$x]['commentcount'];
echo "<div class=’blogpost primary_wide4’><h2>";
echo "<h2>".$title."</h2><img class='left' src='images/image02.jpg' width='250' height='272' alt='' />";
echo "<h3>Posted on ".$date."</h3>";
echo "<p>".$description."</p>";
echo "<p class='meta'>";
echo "<span class='comments'><a href='".$link."'>".$comments."Comments</a></span> ";
echo " <span class='readmore'><a href='".$link."'> View Post</a></span></p>";
echo "</div><br><br>";
}
?>
我如何访问数据(在本例中为 0):
<slash:comments>0</slash:comments>
使用 php?