首页 > 开发 > Php > 正文

php 分析rss代码一段

2020-06-09 12:53:17
字体:
来源:转载
供稿:网友
  1. <?php 
  2. function my_headlines($url) { 
  3.       $rdf = parse_url($url); 
  4.       $fp = fsockopen($rdf['host'], 80, $errno$errstr, 15); 
  5.       if (!$fp) { 
  6.      $content = "<font class="content">Problema!</font>"
  7.      return
  8.       } 
  9.       if ($fp) { 
  10.      fputs($fp"GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0 "); 
  11.      fputs($fp"HOST: " . $rdf['host'] . " "); 
  12.      $string = ""
  13.      while(!feof($fp)) { 
  14.      $pagetext = fgets($fp,300); 
  15.      $string .= chop($pagetext); 
  16.  } 
  17.  fputs($fp,"Connection: close "); 
  18.  fclose($fp); 
  19.  $items = explode("</item>",$string); 
  20.  $content = "<font class="content">"
  21.  for ($i=0;$i<10;$i++) { 
  22.      $link = ereg_replace(".*<link>","",$items[$i]); 
  23.      $link = ereg_replace("</link>.*","",$link); 
  24.      $title2 = ereg_replace(".*<title>","",$items[$i]); 
  25.      $title2 = ereg_replace("</title>.*","",$title2); 
  26.      if ($items[$i] == "") { 
  27.          $content = ""
  28.          return
  29.      } else { 
  30.          if (strcmp($link,$title)) { 
  31.        $cont = 1; 
  32.       $content .= "<img src="images/arrow.gif" border="0" hspace="5"><a href="$link" target="new">$title2</a><br> "
  33.     } 
  34.      } 
  35.  } 
  36.       } 
  37.       echo "$content"
  38. my_headlines 
  39. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表