Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. class rss {
  3.     public $url;
  4.     public $items;
  5.  
  6.     public function __construct($u = false) {
  7.        
  8.     }
  9.    
  10.     public function load($url) {
  11.         $this->items = array();
  12.         $doc = new DOMDocument();
  13.         if(!empty($url)) {
  14.             $doc->load($url);
  15.             foreach ($doc->getElementsByTagName('item') as $node) {
  16.                 $itemRSS = array (
  17.                     'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
  18.                     'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
  19.                     'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
  20.                     'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
  21.                 );
  22.                 array_push($this->items, $itemRSS);
  23.             }
  24.             return $this;
  25.         } else {
  26.             exit("Not valid RSS url given");
  27.         }
  28.     }
  29.    
  30.     public function getItems() {
  31.         foreach($this->items as $i) {
  32.             echo '<div class="item">
  33.                 <div class="item_link"><a href="' . $i['link'] . '">' . $i['title'] .  '</a></div>
  34.             </div>
  35.             <div class="item_desc" style="display: none;">' . $i['desc'] . '</div>';
  36.         }
  37.     }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement