» posted on Monday, February 22nd, 2010 at 12:49am by Dan
PHP RSS Parser – RSS Reader Class for PHP
Just had to create a quick RSS parser for PHP and thought I'd post my solution. The implementation and class follows.
<?php
$rss = new RSSReader('http://news.google.com/?output=rss');
while ($rss -> hasNext())
print_r($rss -> next());
?>
<?php
class RSSReader {
var $xml = null;
var $pos = 0;
var $count = 0;
function __construct($feed_url) {
$this -> load_url($feed_url);
}
function load_url($feed_url) {
$this -> load_string(file_get_contents($feed_url));
}
function load_string($feed_string) {
$this -> xml = simplexml_load_string(str_replace('content:encoded', 'content_encoded', $feed_string));
$this -> pos = 0;
$this -> count = count($this -> xml -> channel -> item);
}
function get_title() {
return $this -> xml -> channel -> title;
}
function get_link() {
return $this -> xml -> channel -> link;
}
function get_pubdate() {
return $this -> xml -> channel -> pubdate;
}
function hasNext() {
return $this -> count > $this -> pos;
}
function next() {
$obj = $this -> xml -> channel -> item[$this -> pos++];
return array(
'title' => (string) $obj -> title,
'link' => (string) $obj -> link,
'description' => (string) $obj -> description,
'content' => (string) $obj -> content_encoded,
'pubDate' => strtotime($obj -> pubDate),
);
}
}
?>
filed under Code | 2 comments
2 Responses to “PHP RSS Parser – RSS Reader Class for PHP”
Leave a Reply
» Keywords
army
asp
buffer
cell phone
Code
css
domain tools
domain valuation
free flv player
freelance
free mp3 player
free mp4 player
google pagerank
haval
internet through cell phone
loading
md5
motorola razr
phone
PR
recordset
sha1
sha256
sha384
sha512
snefru
soldiers
voice mail
web flv player
website monitoring
Web Tools
![[del.icio.us]](http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png)
![[Reddit]](http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png)
free rss parser said:
Jul 09, 10 at 5:59pmThank you for this post ..
Here is another php parser http://bncscripts.com/free-php-rss-parser/
Anna Begum said:
Jul 28, 10 at 4:27amRSS feeds are really great because you are always updated with the latest news or blog posts..”~