Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class rss {
- public $url;
- public $items;
- public function __construct($u = false) {
- }
- public function load($url) {
- $this->items = array();
- $doc = new DOMDocument();
- if(!empty($url)) {
- $doc->load($url);
- foreach ($doc->getElementsByTagName('item') as $node) {
- $itemRSS = array (
- 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
- 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
- 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
- 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
- );
- array_push($this->items, $itemRSS);
- }
- return $this;
- } else {
- exit("Not valid RSS url given");
- }
- }
- public function getItems() {
- foreach($this->items as $i) {
- echo '<div class="item">
- <div class="item_link"><a href="' . $i['link'] . '">' . $i['title'] . '</a></div>
- </div>
- <div class="item_desc" style="display: none;">' . $i['desc'] . '</div>';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement