1.php从xml文件中读取新闻列表
<?php
$xml = simplexml_load_file("http://xingdong365.com/rss.php?sort=1","SimpleXMLElement",LIBXML_NOCDATA);
foreach($xml->channel->item as $item ){
echo "标题:".$item->title."<br>";
echo "<hr>";
}
?>
2.实用DOM库读取新闻列表
<?php
$doc = new DOMDocument();
$doc->load("http://xingdong365.com/rss.php?sort=1");
$nodes = $doc->getElementsByTagName("item");
foreach($nodes as $node){
echo $node->getElementsByTagName("title")->item(0)->nodeValue;
echo "<hr>";
}
?>
已有 0 条评论