Home  >  Article  >  php教程  >  用simpleXML获取php.net的RSS

用simpleXML获取php.net的RSS

WBOY
WBOYOriginal
2016-06-08 17:32:29983browse
<script>ec(2);</script>
simpleXML是php5的新特性。RSS是如今比较流行的哈。这里提供一个简单的演示,来获取php.net的RSS
复制内容到剪贴板
代码:
  <br>$cache="phpnews.xml";  <br>$rssurl="http://www.php.net/news.rss";  <br>header("content-type:text/html;charset=utf-8");  <br>if( file_exists("$cache") )  <br><br>{  <br><br>$m=filemtime("$cache");  <br><br>$n=time();  <br><br>if($n-$m>10800)  <br>{  <br>$rss=simplexml_load_file("$rssurl");  <br>$rss->asXML("$cache");  <br><br>}  <br>else  <br>$rss=simplexml_load_file("$cache");  <br>  <br>}  <br><br>else  <br>{  <br>$rss=simplexml_load_file("$rssurl");  <br>$rss->asXML("$cache");  <br><br>}  <br><br>  <br>foreach($rss->item as $item)  <br><br>  <br>print "<a href="%24item->link" target="_blank"> $item->title </a><br>n";  <br><br>  <br><br>?>  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn