用simpleXML获取php.net的RSS
simpleXML是php5的新特性。RSS是如今比较流行的哈。这里提供一个简单的演示,来获取php.net的RSS。
复制内容到剪贴板
代码:
<?php $cache="phpnews.xml"; $rssurl="http://www.php.net/news.rss"; header("content-type:text/html;charset=utf-8"); if( file_exists("$cache") ) { $m=filemtime("$cache"); $n=time(); if($n-$m>10800) { $rss=simplexml_load_file("$rssurl"); $rss->asXML("$cache"); } else { $rss=simplexml_load_file("$cache"); } else { $rss=simplexml_load_file("$rssurl"); $rss->asXML("$cache"); } foreach($rss->item as $item) { print "<a href="$item->link" target=_blank> $item->title </a><br>n"; }
教程网址:http://www.phprm.com/code/6638026c6a498586772f9bdb6f8bc040.html
欢迎收藏∩_∩但请保留本文链接。