频道直达 - 专题 - 新闻 - 基础 - 高级 - 安装 - 技巧 - 数据库 - 手册 - PHP - Linux - Java - MySQL - Apache - 麻辣堂 - 狼盟 - Rails社群 - 搜索 - 下载 - 开源 - 论坛

php 分析rss代码一段

来源:www.phpres.com 作者:Angelover 出处:www.phpres.com 2007-9-8 08:57:14 进入讨论组
关 键 词: 代码 fp link content rdf if ereg_replace items fputs

php 分析rss代码一段

 

<?php
function my_headlines($url) {
    $rdf = parse_url($url);
    $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
    if (!$fp) {
        $content = "<font class="content">Problema!</font>";
        return;
    }
    if ($fp) {
        fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0 ");
        fputs($fp, "HOST: " . $rdf['host'] . " ");
        $string = "";
        while(!feof($fp)) {
     $pagetext = fgets($fp,300);
     $string .= chop($pagetext);
 }
 fputs($fp,"Connection: close ");
 fclose($fp);
 $items = explode("</item>",$string);
 $content = "<font class="content">";
 for ($i=0;$i<10;$i++) {
     $link = ereg_replace(".*<link>","",$items[$i]);
     $link = ereg_replace("</link>.*","",$link);
     $title2 = ereg_replace(".*<title>","",$items[$i]);
     $title2 = ereg_replace("</title>.*","",$title2);
     if ($items[$i] == "") {
         $content = "";
         return;
     } else {
         if (strcmp($link,$title)) {
          $cont = 1;
      $content .= "<img src="images/arrow.gif" border="0" hspace="5"><a href="$link" target="new">$title2</a><br> ";
  }
     }
 }
    }
    echo "$content";
}

my_headlines("http://bbs.chinaunix.net/rss/46.xml");
?>

欢迎进入PHP开发资源论坛讨论。
收藏此文】【 】【打印】【关闭
相关文章
图文推荐
论 坛 资 源
PHP开发资源网奋斗目标
阅读排行:
热门技术文档
最新图文档
本站编辑推荐:(本站开通Delphi4PHP专区,欢迎进入论坛交流!)
编缉最近更新文章
网站赞助商
搜索您感兴趣的内容
 
   网站首页 -  网站地图 -  网站合作 -  手册中心 -  通用网址 -  网站论坛 -  网站投稿 -  友情链接 -  帮助中心
版权所有:PHP开发资源网 © 2003-2008 通用网址:PHP资源网 合作媒体: 赛迪网IT技术
互联网违法和不良信息举报中心 | 不良信息举报信箱