Tizag Webmaster Forums  

Go Back   Tizag Webmaster Forums > Web Development > Server-Side Scripting > PHP Forum

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2007, 08:40 PM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
(Class) RSS

This class has 3 functions that might help you with RSS

Class
PHP Code:
<?php
class rss{
    var 
$items = array();
    function 
add($a$b){ // Adds a rss item
        
$this->items array_merge($this->items, array(array("title" => $a"link" => $b)));
    }
    function 
write($a){ // Prints out the all items, in RSS style, defined by add()
        
$out '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
    <channel>
        <title>'
.$a.'</title>';
        foreach(
$this->items as $items){
            
$out .= "
            <item>
                <title>"
.$items['title']."</title>
                <link>"
.$items['link']."</link>
            </item>"
;
        }
        
$out .= '
    </channel>
</rss>'
;
        return 
$out;
    }
    function 
read($a$b){ //Get the title and link out of RSS feed
        
$cr 0;
        
$p = array();
        
$a file_get_contents($a);
        while(
$cr != $b){
            
$i strings::get($a"<item>""</item>");
            
$l = array(array("title" => strings::get($i"<title>""</title>"), "link" => strings::get($i"<link>""</link>")));
            
$p array_merge($p$l);
            
$k strings::get($a"<item>""</item>");
            
$a str_replace("<item>".$k."</item>"""$a);
            ++
$cr;
        }
        return 
$p;
    }
}
?>
Example
PHP Code:
<?php
/*
Class
*/
header("Content-Type: application/xml");
$rss = new rss;
$rss->add("tizag""http://www.tizag.com/");
$rss->add("digg""http://www.digg.com/");
$rss->write("sample");
?>
__________________
techietim - jcite
<><
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:09 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2008, Tizag