Witam
Mam pewnien problem ze skryptem php ktory ponizej umiescilem, a mianowicie nie wyswietla mi zawartosci pliku xml z tego kanalu http://www.gofin.pl/rss/podatki.xml
Plik jest pobierany na serwer lecz nie jest on wyswietlany na stronie. Nie wiem czy tkwi problem prosze o pomoc.

Jesli ktos ma inny dobry skrypt ktory jest kompatybilny z tym kanalem rss i wyswietla go na stronie to bardzo prosze o podanie jego nazwy lub umieszczenie na jakis serwer.

Tutaj znajduje sie skrypt z ktorym mam problem:

  1. <?php
  2. /************************************************************
  3. RSS Fetch 0.4.1
  4. RSS Feed Reader
  5. Author: Drew Phillips
  6. www.neoprogrammers.com
  7. Copyright 2005 Drew Phillips
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  22.  
  23.  
  24.  
  25. ************************************************************/
  26.  
  27.  
  28.  
  29. class rss_parser {
  30.   var $update_interval = 60;    
  31.   /* How often to fetch the rss file
  32.      A cached version will be used between updates    */
  33.  
  34.   var $data_directory = "/home/neoprog/www/rss";
  35.   /* Where to store the rss data from the feeds
  36.      Note: an absolute path is better than a relative path here
  37.      unless you plan on keeping the script to display the feeds
  38.      in the same folder as this file and the feeds.   */
  39.  
  40.  
  41.  
  42.   /* NO NEED TO EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING  */
  43.  
  44.  
  45.   var $rss_url;
  46.   var $num_to_show;
  47.   var $do_update;
  48.   var $tags = array();
  49.   var $content;
  50.   var $rss = array();
  51.  
  52.   var $feed_title;
  53.   var $feed_link;
  54.   var $feed_description;
  55.  
  56.   var $my_html;
  57.  
  58.   function rss_parser($url, $numtoshow = 10, $html = "", $update = 0)
  59.   {
  60.     $this->rss_url = $url;
  61.     $this->num_to_show = $numtoshow;
  62.     $this->do_update = $update;
  63.     $this->my_html = preg_replace("/(#{.*?):(.*?})/", "1__2", $html); //xx:xx tag workaround
  64.  
  65.     $this->content = $this->fetch_feed();
  66.     $this->parse_feed();
  67.     $this->show();
  68.   }
  69.  
  70.  
  71.   /* string */
  72.   function fetch_feed()
  73.   { 
  74.     $url_parts = parse_url($this->rss_url);
  75.  
  76.     $filename = $url_parts['host'] . str_replace("/", ",", $url_parts['path']) . "_" . @$url_parts['query'];
  77.     if(file_exists($this->data_directory . "/$filename")) {
  78.       $last = filemtime($this->data_directory . "/$filename");
  79.       if(time() - $last > $this->update_interval * 60 || $this->update_interval == 0) {
  80.         $update = 1;
  81.       }
  82.     } else {
  83.         $create= 1;
  84.     }
  85.  
  86.     if($create == 1 || ($this->do_update == TRUE && $update == 1)) {
  87.       $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5);
  88.       if (!$fp) {
  89.         echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br />\n";
  90.         return;
  91.       }
  92.  
  93.       fputs($fp, "GET " . $url_parts['path'] . "?" . @$url_parts['query'] . " HTTP/1.0r\n"
  94.                 ."Host: " . $url_parts['host'] . "r\n"
  95.                 ."User-Agent: Drew's RSS Reader 0.1r\n"
  96.                 ."Connection: Closer\nr\n");
  97.  
  98.       while(!feof($fp)) {
  99.         $rss_data .= @fgets($fp, 1024);
  100.       }
  101.  
  102.       list(, $rss_data) = explode("r\nr\n", $rss_data, 2);
  103.  
  104.       $output = @fopen($this->data_directory . "/$filename", "w+");
  105.       if(!$output) {
  106.         return $rss_data;
  107.       } else {
  108.         flock($output, LOCK_EX);
  109.         fputs($output, $rss_data);
  110.         flock($output, LOCK_UN);
  111.         fclose($output);
  112.       }
  113.     } //update
  114.  
  115.     return file_get_contents($this->data_directory . "/$filename");
  116.   }
  117.  
  118.   /* void */
  119.   function parse_feed()
  120.   {
  121.     preg_match("/<title>(.*?)</title>/", $this->content, $title);
  122.     $this->feed_title = @$title[1];
  123.  
  124.     preg_match("/<link>(.*?)</link>/", $this->content, $link);
  125.     $this->feed_link = @$link[1];
  126.  
  127.     preg_match("/<description>(.*?)</description>/", $this->content, $description);
  128.     $this->feed_description = @$description[1];
  129.  
  130.     preg_match_all("/<item[^>]*>(.*?)</item>/s", $this->content, $items);
  131.     if (sizeof($items[0]) == 0) {
  132.       echo "No item elements found in rss feed.<br />\n";
  133.     }
  134.  
  135.     for($i = 0; $i < sizeof($items[0]); ++$i) {
  136.       preg_match_all("/(?:<([w:]*)[^>]*>(?:<![CDATA[)?(.*?)(?:]]>)?</1>)+?/si", preg_replace("/<item[^>]*>/", "", $items[0][$i]), $elements);
  137.       for($j = 0; $j < sizeof($elements[0]); ++$j) {
  138.         $elements[1][$j] = str_replace(":", "__", $elements[1][$j]);  //regex fix for items with : like dc:date
  139.         $this->rss[$i][$elements[1][$j]] = trim(html_entity_decode($elements[2][$j]));
  140.       }
  141.     }
  142.   }
  143.  
  144.   
  145.   /* void */
  146.   function show()
  147.   {
  148.     if($this->my_html == "") {
  149.       $this->show_html();
  150.     } else {
  151.       $this->show_user_html();
  152.     }
  153.   }
  154.  
  155.   function show_html()
  156.   {
  157.     $show = (sizeof($this->rss)  > $this->num_to_show ? $this->num_to_show : sizeof($this->rss));
  158.     for($i = 0; $i < $show; ++$i) {
  159.       echo "- <a href=\"{$this->rss[$i]['link']}\" target=\"_new\">{$this->rss[$i]['title']}</a><br />\n";
  160.     }
  161.   }
  162.  
  163.   function show_user_html()
  164.   {
  165.     $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss));
  166.     for($i = 0; $i < $show; ++$i) {
  167.       extract($this->rss[$i]);
  168.       $item = preg_replace("/#{([^}]+)}/e", "$1", $this->my_html);
  169.       echo $item;
  170.     }
  171.   }
  172.  
  173. } // end class
  174.  
  175.  
  176. ?>


  1. <!--
  2.   To include this sample on your homepage, make sure the page's extension is .php
  3.   and inside it put
  4.   include "example.php";
  5.   just make sure example is in the same folder as your main page.
  6. -->
  7.  
  8. <table style="background-color: #FFFFFF; border: solid 1px #000000;" cellpadding="2" cellspacing="1" width="70%" align="center">
  9.   <tr>
  10.     <td style="background-color: #0096D2; font-weight: bold; color: #FFFFFF; font-size: 14px; text-align: center;" width="75%" align="center">
  11.       CNN News: Politics
  12.     </td>
  13.   </tr>
  14. <?php
  15. include_once "./rss_fetch.php";
  16.  
  17. $html  = "  <tr>\n";
  18. $html .= "    <td style='background-color: #DCF0FA; font-weight: bold; color: #000000; font-size: 13px;'>\n";
  19. $html .= "      <font size='+1'><a href='#{link}' target='_new'>#{title}</a></font><br />\n";
  20. $html .= "      #{description}<br />\n";
  21. $html .= "      <font size='2'>#{pubDate}<br /><br />\n";
  22. $html .= "    </td>\n";
  23. $html .= "  </tr>\n";
  24.  
  25. $rss = new rss_parser("http://rss.cnn.com/rss/cnn_allpolitics.rss", 5, $html, 1);
  26. ?>
  27. </table>