Home > php教程 > php手册 > php读取rss feed一例

php读取rss feed一例

WBOY
Release: 2016-06-06 19:55:49
Original
1545 people have browsed it

RSS Feeds如今应用的非常广泛,基本上的网站都有这个功能,用来方便用户订阅最新的文章信息。 下面给出一个php读取rss feed的代码例子: ? phpheader ( Content-type: text/html; charset=utf-8 ); $file = file_get_contents ( http://www.3aj.cn/site/rss.

RSS Feeds如今应用的非常广泛,基本上的网站都有这个功能,用来方便用户订阅最新的文章信息。

 

下面给出一个php读取rss feed的代码例子:

 

<span></span><span>php
header</span><span>(</span><span>"Content-type: text/html; charset=utf-8"</span><span>);</span><span>

$file </span><span>=</span><span> file_get_contents</span><span>(</span><span>"http://www.3aj.cn/site/rss.xml"</span><span>);</span><span>
$xml </span><span>=</span><span>new</span><span>SimpleXMLElement</span><span>(</span><span>$file</span><span>);</span><span>foreach</span><span>(</span><span>$xml</span><span>-></span><span>channel</span><span>-></span><span>item </span><span>as</span><span> $feed</span><span>){</span><span>
    echo $feed</span><span>-></span><span>title</span><span>.</span><span>'<br>'</span><span>;</span><span>
    echo $feed</span><span>-></span><span>link</span><span>.</span><span>'<br>'</span><span>;</span><span>
    echo </span><span>'<br><br>'</span><span>;</span><span>}</span><span>?></span>
Copy after login

 

输出类似如下:

 

php生成随机密码
http://3aj.cn/php/93.html


php 计算"多久之前" 函数
http://3aj.cn/php/92.html


php读取csv文件简单一例
http://3aj.cn/php/91.html


php获取文件名后缀
http://3aj.cn/php/90.html


php计划任务
http://3aj.cn/php/89.html


Linux常用命令大全
http://3aj.cn/linux/88.html

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