当前位置:
首页 > RSS技术 > php动态生成rss
欧洲展区 of 金佳吉国际连锁网上展览会 | 欢迎生产厂家参展、营销企业合作展出。

php动态生成rss

<?php
include_once("inc/conn.php");
include_once("inc/function.php");
$fp = fopen ("temp1.xml","r");
$content = fread ($fp,filesize ("temp1.xml")); #读入打开文件的内容;
$filename = "rss.xml"; #拟将rss.xml文件最后生成在test目录下,test目录要具有写权限;
$handle = fopen ($filename,"w"); #fopen,即打开文件,若文件不存在,则自动创建;
if (!is_writable ($filename)){die ("文件:".$filename."不可写,请检查其属性后重试!");}
if (!fwrite ($handle,$content)){die ("生成文件".$filename."失败!");}
$i=0;
$result= $db->query("select * from  order by id desc");
$k = mysql_num_rows($result);

while( $i< $k )
{
$result= $db->query("select * from order by id desc limit $i,1");
$a = mysql_fetch_array($result);
$b=$a['id'];
$i++;
$title = $a['title'];
$link = "http://www.jz580.net/php?id='$b'";
$time=$a['time'];
$maintext=$a['content'];
$str=trim(strip_tags(substr($maintext,0,30)),"&nbsp;");
$fp = fopen ("temp2.xml","r");
$content = fread ($fp,filesize ("temp2.xml"));
$content = str_replace ("{title}",$title,$content); #替换模板变量中的数据;
$content = str_replace ("{link}",$link,$content);
$content = str_replace ("{maintext}",$str,$content);
$content = str_replace ("{time}",$time,$content);
$filename = "rss.xml";
$handle = fopen ($filename,"a"); #注意这里是a,不是w,因为要追加不是覆盖数据。
if (!is_writable ($filename)){die ("文件:".$filename."不可写,请检查其属性后重试!");}
if (!fwrite ($handle,$content)){die ("生成文件".$filename."失败!");}
}
$fp = fopen ("temp3.xml","r");
$content = fread ($fp,filesize ("temp3.xml"));
$filename = "rss.xml";
$handle = fopen ($filename,"a");
if (!is_writable ($filename)){die ("文件:".$filename."不可写,请检查其属性后重试!");}
if (!fwrite($handle,$content)){die ("生成文件".$filename."失败!");}
fclose ($handle);
die ("成功!");
?>

三个文件

<?xml version="1.0" encoding="gb2312" ?>
<rss version="2.0">
<channel>
<title> 桔子帮玩游戏赚钱 </title>
<link />http://www.jz580.net
<description>桔子帮-玩游戏赚钱…………</description>
<language>zh-cn</language>
<generator>冲天科技 版权所有</generator>
<webmaster>admin@jz580.net</webmaster>
 
<item>
    <title> {title} </title>
    <link /> {link} 
    <description> {maintext} </description>
    <pubdate> {time} </pubdate>
</item>
 
</channel>
</rss>

(来源:lichong827510的博客 2012-02-04 01:36
http://maorongxiong.wap.blog.163.com/w2/blogDetail.do?blogId=fks_087067092095083067086080081074072087089065092087086066092080&p=3&hostID=maorongxiong)

php动态生成rss:等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!