Home > php教程 > PHP源码 > body text

用simpleXML获取php.net的RSS

WBOY
Release: 2016-06-08 17:32:29
Original
1019 people have browsed it
<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>?>  

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!