Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]czytnik RSS dodanie do tabeli
Forum PHP.pl > Forum > Przedszkole
zgredo
Witam,
mam następujący problem otóż nie wiem jak zrobić taki skrypt aby w tabeli pobierał mi dane z nagłówków z kanału RSS i abym resztę sam dodał.
mam już tyle :
  1. <?php
  2.  
  3. class Rss {
  4.  
  5. public $rssFile;
  6. public $cacheFile;
  7. public $xml;
  8. private $cacheDir;
  9.  
  10. public function __construct ( $rssFile , $cache = 'on' , $cacheDir = 'cache' )
  11. {
  12. $this->rssFile = $rssFile;
  13. $this->cacheFile = basename ( $this->rssFile );
  14. $this->cacheDir = $cacheDir;
  15.  
  16. if ( empty ( $this->rssFile ) OR empty( $cacheDir ) ) exit;
  17.  
  18. if ( $cache == 'on' ) {
  19. if ( file_exists ( $this->cacheDir . '/' . $this->cacheFile . '.php' ) ) {
  20. $this->xml = simplexml_load_file ( 'cache/' . $this->cacheFile . '.php' );
  21. } else {
  22. $this->xml = simplexml_load_file ( $this->rssFile );
  23. $cacheFileCode = file_get_contents ( $this->rssFile );
  24.  
  25. $fp = fopen ( $this->cacheDir . '/' . $this->cacheFile . '.php' , 'w' );
  26. fwrite ( $fp , $cacheFileCode );
  27. fclose ( $fp );
  28. }
  29. } else {
  30. $this->xml = simplexml_load_file ( $this->rssFile );
  31. }
  32. }
  33.  
  34. public function clearAllCache ()
  35. {
  36. foreach ( glob($this->cacheDir . "/*.php") as $fileCacheName ) {
  37. unlink ( $fileCacheName );
  38. }
  39. }
  40.  
  41. public function clearOneCache ( )
  42. {
  43. unlink ( $this->cacheDir . '/' . $this->cacheFile . '.php' );
  44. }
  45.  
  46. public function rssInfo ()
  47. {
  48. $arr['version'] = $this->xml->attributes();
  49. $arr['title'] = $this->xml->channel->title;
  50. $arr['description'] = $this->xml->channel->description;
  51.  
  52. return $arr;
  53. }
  54.  
  55. public function getRss()
  56. {
  57. return $this->xml->channel->item;
  58. }
  59.  
  60. }
  61.  
  62. ?>


ps. chciałbym aby te tabele były jedna pod drugą takie jakby tabelę po kilka na stronie. Jestem ciemny w tych tematach wiem tylko tyle, że trzeba dodać pętlę for w miejscu gdzie są pobierane nagłówki .

Pozdrawiam.
zgredo
nie mogę już edytować sad.gif chodziło mi o ten kod :
  1. <?php
  2. //header("Content-Type: text/html; charset=iso-8859-2");
  3. //RSSerPHP
  4. //Autor: Saletra
  5.  
  6.  
  7. /* Zmienne, kolejno: czas odświeżania (w minutach - należy zmieniać wyłącznie liczbę), ilość pobieranych elementów, plik cache, adres XML-a */
  8. $czas = '1 minutes';
  9. $ileRss = 1;
  10.  
  11. //Folder dla pliku cache musi mieć CHMOD 777.
  12. $file = "rss/cache.htm";
  13. $plikRss = 'http://feeds.feedburner.com/AndroidTapp?format=xml';
  14.  
  15. // Sprawdza czy plik trzeba odswiezyc, jeśli nie, wyświetla dane z cache
  16. if(is_file($file) && (date('d-m-Y H:i:s', filemtime($file))) >= date('d-m-Y H:i:s', strtotime($czas))){
  17.  
  18.  
  19. // Buduje plik cache
  20. } else {
  21. $doc = new DOMDocument();
  22. $doc->load($plikRss);
  23. $i=0;
  24.  
  25. if(is_file($file)){
  26. $wyczysc = file_put_contents($file, '');
  27. }
  28. $fp = fopen($file, "w+");
  29. foreach ($doc->getElementsByTagName('item') as $node) {
  30. if($i>=$ileRss){
  31. break;
  32. }
  33. $i++;
  34. $itemRSS = array (
  35. 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
  36.  
  37. );
  38. /* Konwertuje z UTF-8 na ISO-8859-2, można włączyć jeśli są problemy z polskimi znakami. Wymagane iconv na serwerze */
  39. $itemRSS['title'] = iconv('UTF-8', 'ISO-8859-2', $itemRSS['title']);
  40.  
  41. $link = "<a href='".$itemRSS['link']."'>".nl2br($itemRSS['title'])."...</b> ";
  42. echo nl2br($link);
  43. fwrite($fp, $link);
  44. }
  45. fclose($fp);
  46. }
  47. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.