加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php 剖析rss代码一段

发布时间:2023-04-11 14:23:18 所属栏目:PHP教程 来源:
导读:<?php

function my_headlines($url) {

$rdf = parse_url($url);

$fp = fsockopen($rdf[&#39;host&#39;], 80, $errno, $errstr, 15);

if (!$fp) {

$content = "<font cla
<?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
 
?>
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!