Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Daniel Tlach  >  RSS Feed Reader  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: RSS Feed Reader
Parse and display items of an RSS feed
Author: By
Last change: - added exceptions
- changed settings to constants
- added category printing
Date: 3 years ago
Size: 1,435 bytes
 

Contents

Class file image Download
<?php

header
'Content-Type: text/html; charset=utf-8' );

error_reporting(E_ALL);
ini_set('display_errors'true);

include 
'./Rss.minified.php'// include library

$Rss = new Rss// create object

/*
    XML way
*/
try {
    
$feed $Rss->getFeed('http://blog.danaketh.com/rss/items'Rss::XML);
    echo 
'<pre>';
    foreach(
$feed as $item)    {
        echo 
"<b>Title:</b> <a href=\"$item[link]\">$item[title]</a>\n";
        echo 
"<b>Published:</b> $item[date]\n";
        echo 
"<b>Category:</b> $item[category]\n";
        echo 
"\n$item[description]\n";
        echo 
"<hr/>";
    }
    echo 
'</pre>';
}
catch (
Exception $e) {
    echo 
$e->getMessage();
}

/*
    SimpleXML way
*/
try {
    
$feed $Rss->getFeed('http://blog.danaketh.com/rss/items'Rss::SXML);
    echo 
'<pre>';
    foreach(
$feed as $item)    {
        echo 
"<b>Title:</b> <a href=\"$item[link]\">$item[title]</a>\n";
        echo 
"<b>Published:</b> $item[date]\n";
        echo 
"<b>Category:</b> $item[category]\n";
        echo 
"\n$item[description]\n";
        echo 
"<hr/>";
    }
    echo 
'</pre>';
}
catch (
Exception $e) {
    echo 
$e->getMessage();
}

/*
    Text way
*/
try {
    
$feed $Rss->getFeed('http://blog.danaketh.com/rss/items'Rss::TXT);
    echo 
'<pre>';
    foreach(
$feed as $item)    {
        echo 
"<b>Title:</b> <a href=\"$item[link]\">$item[title]</a>\n";
        echo 
"<b>Published:</b> $item[date]\n";
        echo 
"<b>Category:</b> $item[category]\n";
        echo 
"\n$item[description]\n";
        echo 
"<hr/>";
    }
    echo 
'</pre>';
}
catch (
Exception $e) {
    echo 
$e->getMessage();
}