思章老师
思章老师

读取RSS Feed PHP代码

为了实现网站页面里读取RSS Feed内容并显示,从网上找了两个不错的代码,进行详细研究,也给有同样需要的朋友一个借鉴。

下页这个是引自肥肥龙的:

<?php
//RSS源地址列表数组
$rssfeed = array(“http://www.blog-dragon.com/feed”,
“http://rss.sina.com.cn/news/allnews/sports.xml”,
“http://ent.163.com/special/00031K7Q/rss_toutiao.xml”,
“http://tech.163.com/special/00091JPQ/techimportant.xml”); //设置编码为UTF-8
header(‘Content-Type:text/html;charset= UTF-8’); for($i=0;$i<sizeof($rssfeed);$i++){//分解开始
$buff = “”;
$rss_str=””;
//打开rss地址,并读取,读取失败则中止
$fp = fopen($rssfeed[$i],”r”) or die(“can not open $rssfeed”);
while ( !feof($fp) ) {
$buff .= fgets($fp,4096);
}
//关闭文件打开
fclose($fp); //建立一个 XML 解析器
$parser = xml_parser_create();
//xml_parser_set_option — 为指定 XML 解析进行选项设置
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
//xml_parse_into_struct — 将 XML 数据解析到数组$values中
xml_parse_into_struct($parser,$buff,$values,$idx);
//xml_parser_free — 释放指定的 XML 解析器
xml_parser_free($parser); foreach ($values as $val) {
$tag = $val[“tag”];
$type = $val[“type”];
$value = $val[“value”];
//标签统一转为小写
$tag = strtolower($tag); if ($tag == “item” && $type == “open”){
$is_item = 1;
}else if ($tag == “item” && $type == “close”) {
//构造输出字符串
$rss_str .= “<a href='”.$link.”‘ target=_blank>”.$title.”</a><br />”;
$is_item = 0;
}
//仅读取item标签中的内容
if($is_item==1){
if ($tag == “title”) {$title = $value;}
if ($tag == “link”) {$link = $value;}
}
}
//输出结果
echo $rss_str.”<br />”;
}
?>

下面这个是来自CSDN的代码:

[前言]
在个人建站的过程中,经常要从其他网站获取大量动态信息。
本文所描述的就是使用php程序读取rss标准的xml格式文件,动态显示他人站点的信息列表。

[前提]
对于php编程爱好者来说,前期的准备相对简单,只要有php4以上的环境就可以建立此功能。

[对应的XML/RSS文件的格式]
基本上很多网站提供的用来做rss浏览的文件都是以下的格式,这是符合xml的w3c通用标准的。
简单的分析一下,
基本的树结构是,
一个rss根下,有一个channel节点,
该channel节点下的title,link,description属性是常用的,
然后就是item节点,众多item节点是最近跟新的若干篇文章,
该item节点下的title,link,pubDate,description属性是常用的。
简单格式如下:

<rss version=”2.0″ xmlns:dc=”http://purl.org/dc/elements/1.1/” xmlns:trackback=”http://madskills.com/public/xml/rss/module/trackback/” xmlns:wfw=”http://wellformedweb.org/CommentAPI/” xmlns:slash=”http://purl.org/rss/1.0/modules/slash/”>

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<channel>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>本站点频道的标题</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>链接地址</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>站点频道描述信息</description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>文章1</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>文章1链接地址</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>文章1内容简介</description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>文章2</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>文章2链接地址</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>文章2内容简介</description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</channel>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</rss>

举例:

– <rss version=”2.0″ xmlns:dc=”http://purl.org/dc/elements/1.1/” xmlns:trackback=”http://madskills.com/public/xml/rss/module/trackback/” xmlns:wfw=”http://wellformedweb.org/CommentAPI/” xmlns:slash=”http://purl.org/rss/1.0/modules/slash/”>

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
– <channel>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>邢晓宁专栏</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>http://blog.csdn.net/thefirstwind/</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>代码一生</description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<dc:language>af</dc:language>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<generator>.Text Version 1.0.1.1</generator>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<image>http://counter.csdn.net/pv.aspx?id=72</image>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
– <item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<dc:creator>♂猜猜♂(邢晓宁)</dc:creator>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>在 MS Windows 下建立 DocBook 的解譯環境</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>http://blog.csdn.net/thefirstwind/archive/2006/12/21/1451714.aspx</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<pubDate>Thu, 21 Dec 2006 13:50:00 GMT</pubDate>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<guid>http://blog.csdn.net/thefirstwind/archive/2006/12/21/1451714.aspx</guid>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<wfw:comment>http://blog.csdn.net/thefirstwind/comments/1451714.aspx</wfw:comment>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<comments>http://blog.csdn.net/thefirstwind/archive/2006/12/21/1451714.aspx#Feedback</comments>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<slash:comments>0</slash:comments>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<wfw:commentRss>http://blog.csdn.net/thefirstwind/comments/commentRss/1451714.aspx</wfw:commentRss>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<trackback:ping>http://tb.blog.csdn.net/TrackBack.aspx?PostId=1451714</trackback:ping>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>在 MS Windows 下建立 DocBook 的解譯環境<img src =”http://blog.csdn.net/thefirstwind/aggbug/1451714.aspx” width = “1” height = “1” /></description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
– <item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<dc:creator>邢晓宁</dc:creator>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>程序员学习的革命-如何使用大脑</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link>http://blog.csdn.net/thefirstwind/archive/2006/12/13/1440965.aspx</link>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<pubDate>Wed, 13 Dec 2006 09:41:00 GMT</pubDate>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<guid>http://blog.csdn.net/thefirstwind/archive/2006/12/13/1440965.aspx</guid>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<wfw:comment>http://blog.csdn.net/thefirstwind/comments/1440965.aspx</wfw:comment>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<comments>http://blog.csdn.net/thefirstwind/archive/2006/12/13/1440965.aspx#Feedback</comments>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<slash:comments>27</slash:comments>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<wfw:commentRss>http://blog.csdn.net/thefirstwind/comments/commentRss/1440965.aspx</wfw:commentRss>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<trackback:ping>http://tb.blog.csdn.net/TrackBack.aspx?PostId=1440965</trackback:ping>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<description>很多人搞技术,还有很多转行搞技术,搞了一段时间终于发现,自己不适合作技术,要我说其实就是用脑方式的问题。真的学会适当的用脑方式,编程编起来得心应手。<img src =”http://blog.csdn.net/thefirstwind/aggbug/1440965.aspx” width = “1” height = “1” /></description>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</item>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</channel>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</rss>

[核心程序]

<?php

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$RSSURL = “http://blog.csdn.net/thefirstwind/Rss.aspx”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$buff = “”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$fp = fopen($RSSURL,”r”);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
while ( !feof($fp) ) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$buff .= fgets($fp,4096);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
fclose($fp);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$parser = xml_parser_create();
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parse_into_struct($parser,$buff,$values,$idx);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parser_free($parser);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 0;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
foreach ($values as $value) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$tag = $value[“tag”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$type = $value[“type”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$value = $value[“value”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$tag = strtolower($tag);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
if ($tag == “item” && $type == “open”) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 1;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
} else if ($tag == “item” && $type == “close”) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
echo <<<EOM
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$title
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$link
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$description
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
EOM;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 0;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
if ($in_item) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
switch ($tag) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “title”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$title = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “link”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$link = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “description”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$description = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
?>

[配合上以上说明,完整的源代码如下]

<?php

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://www3.asahi.com/rss/index.rdf”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://rss.news.yahoo.com/rss/topstories”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$RSSURL = “http://blog.csdn.net/thefirstwind/Rss.aspx”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://jlinux.ddo.jp/bbs/rss.php?auth=0”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://rss.sina.com.cn/news/marquee/ddt.xml”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://rss.sina.com.cn/news/allnews/sports.xml”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
#$RSSURL = “http://rss.sina.com.cn/news/allnews/ent.xml”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$buff = “”;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$fp = fopen($RSSURL,”r”);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
while ( !feof($fp) ) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$buff .= fgets($fp,4096);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
fclose($fp);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$parser = xml_parser_create();
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parse_into_struct($parser,$buff,$values,$idx);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
xml_parser_free($parser);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$channel_title = $values[2][“value”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
echo <<<__HTML__
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<html>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<head>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<title>$channel_title</title>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<link rel=’stylesheet’ type=’text/css’ id=’css’ href=’/bbs/forumdata/cache/style_1.css’>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<script type=’text/javascript’ src=’/bbs/include/common.js’></script>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<script type=’text/javascript’ src=’/bbs/include/menu.js’></script>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</head>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<body>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<table border=’1′>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<tr><td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<img src=’http://www.csdn.net/Images/logo_csdn.gif’>&nbsp;&nbsp;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<!–
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<img src=’http://us.i1.yimg.com/us.yimg.com/i/us/nt/ma/ma_nws_1.gif’>&nbsp;&nbsp;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<img src=’http://jlinux.ddo.jp/bbs/images/default/logo.gif’>&nbsp;&nbsp;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<img src=’http://image2.sina.com.cn/dy/sina_news626.gif’>&nbsp;&nbsp;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
//–>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$channel_title
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$channel_lastBuildDate<br>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
__HTML__;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 0;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
foreach ($values as $value) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$tag = $value[“tag”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$type = $value[“type”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$value = $value[“value”];
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$tag = strtolower($tag);
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
if ($tag == “item” && $type == “open”) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 1;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
} else if ($tag == “item” && $type == “close”) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
echo <<<EOM
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<td colspan=’2′ class=’header’width=’400′>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<a href=”$link”>$title</a>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<td colspan=’2′ width=’400’align=’right’>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$pubDate
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<td colspan=’2′ width=’400′>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$description
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
<td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
&nbsp;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</td>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</tr>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
EOM;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$in_item = 0;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
if ($in_item) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
switch ($tag) {
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “title”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$title = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “link”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$link = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “pubDate”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$pubDate = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
case “description”:
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
$description = $value;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
break;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
}
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
echo <<< __HTMLEND__
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</table>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</body>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
</html>
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
__HTMLEND__;
http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif

http://lisizhang.com/wp-content/uploads/auto_save_image/2010/03/124916AZ9.gif
?>

rss-feed

rss-feed

发表评论

textsms
account_circle
email

思章老师

读取RSS Feed PHP代码
为了实现网站页面里读取RSS Feed内容并显示,从网上找了两个不错的代码,进行详细研究,也给有同样需要的朋友一个借鉴。 下页这个是引自肥肥龙的: <?php //RSS源地址列表数组 $rss…
扫描二维码继续阅读
2010-03-03