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 Md. Rayhan Chowdhury  >  Ray Feed Reader  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script file for feed reader.
Class: Ray Feed Reader
Retrieve and display RSS feeds
Author: By
Last change: Example section updated according to changes in main class..
Date: 4 years ago
Size: 2,615 bytes
 

Contents

Class file image Download
<?php

    ini_set
('display_errors'1);

    
/**
     * Example Usage of RayFeedReader
     */
   
    
require_once('rayfeedreader.php');

    
/**
     * Get Instance of the class.
     */
    
$reader1 RayFeedReader::getInstance();
    
$reader1 RayFeedReader::getInstance(array())->setOptions(array('url' => 'http://raynux.com/blog/feed/atom/'));    
    
$reader2 = new RayFeedReader();
    
$reader3 = new RayFeedReader();
    
    
// Options 1: parse from url
    
$options1 = array(
                        
'url' => "http://raynux.com/blog/feed/atom/",
                    );
    
$data1 $reader1->setOptions($options1)->parse()->getData();
    
    
// Options 2: parse from file    
    
$options2 = array(
                        
'url' => 'feed.xml',
                    );
    
$data2 $reader2->setOptions($options2)->parse()->getData();
    
    
    
// Options 3: parse from string/stream
    
$feedXml file_get_contents("http://raynux.com/blog/feed/atom/");
    
$options3 = array(
                        
'url' => null,
                        
'xml' => $feedXml,
                    );
    
$data3 $reader3->setOptions($options3)->parse()->getData();    
    
    
    
/**
     * HTML widget examples.
     */
    // Options 1: parse from url
    
$options1 = array(
                        
'url' => "http://raynux.com/blog/feed/atom/",
                        
'widget' => 'RayFeedWidget',
                    );
    
    
// Options 2: parse from file    
    
$options2 = array(
                        
'url' => 'feed.xml',
                        
'widget' => 'RayFeedWidget',
                    );
    
    
// Options 2: parse from string/stream
    
$feedXml file_get_contents("http://raynux.com/blog/feed/atom/");
    
$options3 = array(
                        
'url' => null,
                        
'widget' => 'RayFeedWidget',
                        
'xml' => $feedXml,
                    );
    
    
    
/**
     * Load rayFeedWidget class file
     */
    
require_once('rayfeedwidget.php');

    
// OR with widget options.
    
$widgetOptions = array('showTitle' => true);
    
$widgetOptions2 = array('widget' => 'detail''showTitle' => true);
    
    
$html1 RayFeedReader::getInstance()->setOptions($options1)->parse()->widget();
    
    
$html2 RayFeedReader::getInstance()->setOptions($options2)->parse()->widget($widgetOptions);
    
    
$html3 RayFeedReader::getInstance()->setOptions($options3)->parse()->widget($widgetOptions2);
    
    if (!empty(
$html2)) {
        
header('Content-type: text/html; charset=utf-8');
        echo 
$html2;
    } else {
        
var_export(RayFeedReader::getInstance()->getErrors());
    }
?>