CSTrüter HomeArticlesDownloadsAbout meContact me
How to enable the filestream feature in SQL 2008 - Alternative way to store blobs(files) via SQL 2010-08-21 19:31:56
How to create a Singleton Pattern in C# 2010-08-10 22:52:52
How to prevent that threads access shared resources concurrently via Monitor. 2010-08-06 15:31:15
A quick review of the book PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide written by Larry Ullman 2010-08-04 21:48:58
How to prevent that threads access shared resources concurrently via Mutex. 2010-08-03 14:42:36
How to stop propagation of javascript events 2010-07-25 21:59:29
Post about how Pete the web developer fixed his sitemap 2010-07-17 15:12:02
How to setup an out of process session service 2010-07-08 17:51:46
How to display/add images from/to a SQL Database 2010-07-04 23:15:15
How to register a custom URL protocol handler 2010-06-28 20:34:01
Creating a WYSIWYG textbox for your website is actually quite simple. 2007-02-01 12:00:00
Move items between two listboxes in ASP.net(C#, VB.NET) and PHP 2008-06-12 17:07:43
Firefox word wrapping issues 2008-06-09 09:51:21
Populate a TreeView control in a windows application. 2009-08-27 16:01:03
2007-02-22 12:00:00
Download the demo code There is a few methods if you're planning to parse RSS in PHP, depending on your version of PHP, it can prove to be quite tedious. If you're looking for an out of the box solution there are components available in the PEAR package and a number of open source projects, that you can easily use as well. We're however going to code this ourselves, the following code is by no means a mature solution (it assumes a lot of things), and should soley be used as a starting point - ensure that you've got sufficient error handling. In the first example, we're going to use the xml parser functions in PHP to populate our RSS object, we also attach three events (openElement, closeElement and cdata) that aid us in parsing the feed.
<?php class RSSReader { var $inItem = false; var $inChannel = false; var $currentTag = ""; var $items = array(); var $count = 0; function RSSReader($url) { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "openElement", "closeElement"); xml_set_character_data_handler($this->parser, "cdata"); $contents = file_get_contents($url); xml_parse($this->parser, $contents); xml_parser_free($this->parser); } function openElement($parser, $tag, $attributes) { switch($tag) { case "ITEM": $this->inItem = true; $this->inChannel = false; $this->items[$this->count] = array(); break; case "CHANNEL": $this->inChannel = true; } $this->currentTag = strtolower($tag); } function cdata($parser, $cdata) { if ($this->inItem) { if ($this->currentTag != "item") { $this->items[$this->count][$this->currentTag].= $cdata; } } if ($this->inChannel) { if ($this->currentTag == "image") { $this->inChannel = false; } else { $this->.= $cdata; } } } function closeElement($parser, $tag) { if ($tag == "ITEM") { $this->count++; $this->inItem = false; $this->inChannel = false; } } } ?>
<?php class RSSReader { private $inItem = false; private $inChannel = false; private $currentTag = ""; public $items = array(); public $count = 0; public function RSSReader($url) { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "openElement", "closeElement"); xml_set_character_data_handler($this->parser, "cdata"); $contents = file_get_contents($url); xml_parse($this->parser, $contents); xml_parser_free($this->parser); } private function openElement($parser, $tag, $attributes) { switch($tag) { case "ITEM": $this->inItem = true; $this->inChannel = false; $this->items[$this->count] = array(); break; case "CHANNEL": $this->inChannel = true; } $this->currentTag = strtolower($tag); } private function cdata($parser, $cdata) { if ($this->inItem) { if ($this->currentTag != "item") { $this->items[$this->count][$this->currentTag].= $cdata; } } if ($this->inChannel) { if ($this->currentTag == "image") { $this->inChannel = false; } else { $this->.= $cdata; } } } private function closeElement($parser, $tag) { if ($tag == "ITEM") { $this->count++; $this->inItem = false; $this->inChannel = false; } } } ?>
<?php class RSSReader { public $items = array(); public function RSSReader($url) { $xmlDoc = new COM("Microsoft.XMLDOM"); $xmlDoc->async = false; $xmlDoc->load($url); $this->title = $this->getElement($xmlDoc, 'title'); $this->link = $this->getElement($xmlDoc, 'link'); $this->description = $this->getElement($xmlDoc, 'description'); $items = $xmlDoc->getElementsByTagName('item'); for ($i = 0; $i < $items->length; $i++) { $this->items[$i] = array('title' => $this->getElement($items[$i], 'title'), 'description' => $this->getElement($items[$i], 'description'), 'link' => $this->getElement($items[$i], 'link')); } } private function getElement($parent, $tagName) { $element = $parent->getElementsByTagName($tagName); return $element[0]->firstChild->nodeValue; } } ?>
<?php class RSSReader { public function RSSReader($url) { $contents = file_get_contents($url); $rss = new SimpleXmlElement($contents); $this->title = $rss->channel->title; $this->link = $rss->channel->link; $this->decription = $rss->channel->description; $this->date = $rss->channel->pubDate; $this->image = $rss->channel->image; $this->items = $rss->channel->item; } } ?>
No Entries Found
The company I am currently working for as software developer.
Collection of C# snippets 2010-05-22 01:06:19
Collection of MS SQL snippets 2010-05-22 00:55:15
Collection of JavaScript snippets 2010-05-22 00:37:57
Collection of ASP.net snippets 2010-05-22 00:29:56
Collection of PHP snippets 2010-05-22 00:06:45
a Parallel reference of programming languages 2009-09-10 12:48:23
a tutorial explaining how to develop a simple login using PHP and MySQL 2009-09-05 18:26:47
An article looking at adding some kind of event driven model to PHP 5 2008-07-28 12:48:09
It is very simple creating your own rss reader, the following article looks at a few methods of doing this. 2008-06-23 13:18:25
A quick reference about working with dropdown boxes (select element) in javascript. 2007-02-17 16:36:41
Collection of funny programming articles 2006-10-08 14:23:43