tag with class set to rss_post Every author (if displayed) is in a span tag with class set to rss_author Every feed link is in a h4 (wrapped in ) tag with class set to rss_heading Knowing that creating CSS should be trivial. Class diagram of RSSParser: _________________________ |________RSSParser________| | -insideitem : boolean | | -tag : string | | -title : string | | -description : string | | -link : string | | -author : string | | -source : string | | -xml_parser : resource | |_________________________| | +__construct() : void | | +create() : void | | +__destruct() : void | | -startElement() : void | | -endElement() : void | | -characterData() : void | |_________________________| */ class RSSParser { private $insideitem = false; private $tag; private $title; private $description; private $link; private $author; private $source; private $xml_parser; public function __construct($url) { $this->source = $url; $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser,$this); xml_set_element_handler($this->xml_parser, "startElement", "endElement"); xml_set_character_data_handler($this->xml_parser, "characterData"); } public function create() { $xml = file_get_contents($this->source); xml_parse($this->xml_parser, $xml, strlen($xml)) or die("XML error: ".xml_error_string(xml_get_error_code($this->xml_parser))." at line ".xml_get_current_line_number($this->xml_parser)); } public function __destruct() { xml_parser_free($this->xml_parser); } private function startElement($parser, $tagName, $attrs) { if ($this->insideitem) $this->tag = $tagName; elseif ($tagName == "ITEM") $this->insideitem = true; } private function endElement($parser, $tagName) { if ($tagName == "ITEM") { $this->description = preg_replace("//","",$this->description); echo "

\n\t

".$this->title."

\n"; echo "\t".$this->description."\n\n"; #The author field is rare, so only use if it's there if(!empty($this->author)) echo "\t-".$this->author."\n"; echo "

\n"; $this->title = ""; $this->description = ""; $this->link = ""; $this->author = ""; $this->insideitem = false; } } private function characterData($parser, $data) { if ($this->insideitem) { $data = trim($data); switch ($this->tag) { case "TITLE": $this->title .= $data; break; case "DESCRIPTION": $this->description .= $data; break; case "LINK": $this->link .= $data; break; case "AUTHOR": $this->author .= $data; break; } } } } #$rss_parser = new RSSParser('http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml'); $rss_parser = new RSSParser('http://127.0.0.1/cs/index.php?act=rssout&id=2'); $rss_parser->create(); ?>