以前,我们在首页调用,友情调用时,都喜欢用直接查询法和JS调用法,这都需要被调用一方配合才可以做到。
比如说JS调用,必须要有一个文件专门负责查询与返回所调用的数据。
这样的方式显然会受到很多限制。比如说,现在很多人都用新浪,博客中国等的博客站点提供的博客服务,这样用户就没有对博客所在的服务器的控制权,JS调用和直接查询法就会受到限制。
博客是web2.0的典范,就应该有web2.0的解决方案!
现在,几乎每一个博客都有自己的RSS聚合系统,针对RSS,我写了一个小程序,实现了BLOG的同步调用。
PHP代码
- "text/html; charset=utf-8" http-equiv="Content-Type">
- // The file test.xml contains an XML document with a root element
- // and at least an element /[root]/title.
- $xmlfile = date(‘YmdH’).‘.xml’;
- $sourcexml = ‘http://blog.eaxi.com/rss.xml’;
- //die($xmlfile);
- if( !file_exists($xmlfile) ) {
- echo ‘你是第一次访问本系统。正在初始化…’;
- $str = @file($sourcexml) or die(‘加载文件时出错。’);
- $str = join(”,$str);
- $fp = fopen($xmlfile,‘w’) or die(‘写缓存失败!’);
- fputs($fp,$str);
- fclose($fp);
- echo "初始化完毕。";
- }
- if (file_exists($xmlfile)) {
- $xml = simplexml_load_file($xmlfile);
- //print_r($xml);
- $c = &$xml->channel;
- echo ‘
-
.$c->link.‘">’.$c->title.‘
-
’
; - echo ‘
-
’
.$c->lastBuildDate.‘ -
-
’
; - $listhead = ‘
-
序号 标题 作者 类别 评论 时间 - ‘;
- echo $listhead;
- $k = 0;
- foreach($c->item as $v) {
- $k ++;
- echo "
$k $v->title" href="$v->link">$v->title $v->author $v->category 点击发表评论" href="$v->comments">评论 $v->pubDate - ";
- }
- echo ‘
-
’
; - } else {
- exit(‘Failed to open xml file.’);
- }
- ?>
注意:只能在PHP5环境下使用!