欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php 分析rss代码

程序员文章站 2024-01-17 17:44:28
...

rss

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