How to parse RSS feeds with PHP

XML stands for EXtensible Markup Language and it is<image>
a simplified subset of Standard Generalized Markup<title>SoftArea51 - latest XML & CSS
Language (SGML). Its primary purpose is to facilitateUtilities software for Windows</title>
the sharing of data across different information<url>
systems, particularly systems connected via the<link>
Internet. RSS is a Web content syndication format.<description>Try and buy latest XML &
Its name is an acronym for Really Simple Syndication.CSS Utilities software for Windows<
In other words, RSS is a lightweight XML formatdescription>
designed for sharing headlines and other Web</image>
content. More details about RSS 2.0 specification can<item>
be found at Very often people want to read rss files<title>Feed Mix</title>
and display the content on their site using a custom<link>
layout. This article represents a complete guide to<description>Feed Mix is a feature-rich RSS
the entire process of parsing RSS 2.0 files using PHP.editor with the unique ability to create a new RSS
Requirements: In order to be able to test the code infeed from several others that already exist...<
this tutorial we need to have installed a web serverdescription>
(I am using Apache: configured with support for PHP</item>
( You can find lots of articles and tutorials on the<item>
web on how to install Apache and PHP. Available<title>RSS Submit</title>
method for parsing an XML file. Currently there are<link>
two methods used by developers to read XML files,<description>RSS Submit is the most powerful
no matter what the programming language might be:RSS feed promotion tool available...<
SAX (Simple API for XML) and DOM (Documentdescription>
Object Model). I will shortly describe each of these</item>
methods and finally choose the best for us. SAX<item>
(Simple API for XML) is an event based API. Every<title>PAD-Script</title>
time a tag is opened or closed, or any time the<link>
parser finds some text, it makes callbacks to<description>Avoid having to update all your
user-defined functions for each event with the nodePAD files whenever the PAD format changes...<
or text information. The advantage of a SAX parserdescription>
is that it's really lightweight. The parser doesn't keep</item>
anything in memory for very long, so it can be used<item>
for extremely large files. The disadvantage is that<title>PAD Data Extractor Tool</title>
writing SAX parser event function can take some<link>
time and coding experience. The DOM (Document<description>Data Doctor XML PAD information
Object Model) defines a standard way for accessingextractor software tools extract important data
and manipulating XML documents. The DOM presentsfrom online website XML file...</description>
an XML document as a tree-structure (a node tree),</item>
with the elements, attributes, and text defined as</channel>
nodes. An API implementing DOM standard will read</rss>
the entire XML document into memory and provide aIn order to get the useful data from the RSS file we
set of functions for manipulating the data. Theneed to loop through the item nodes and extract the
drawback of this powerful method is that is notinformation we need. Below you can find the script
recommended for large XML documents, which wouldfor parsing the above RSS feeds:
take too much memory to build the model of the<?php
document. Because usually people are dealing with$doc = new DOMDocument();
normal size files and not everybody has the$doc->load('
necessary time or skills to write an entire SAX parser$arrFeeds = array();foreach
we'll use the DOM method. So let's get started. As a($doc->getElementsByTagName('item') as $node)
RSS example we'll use the following file: A part of{array_push($arrFeeds, array ( 'title' =>
this file is given below.>nodeValue,
<?xml version=\"1.0\" encoding=\"UTF-8\"?>'description' =>
<rss version=\"2.0\">em(0)->nodeValue,
<channel>'link' =>
<title>SoftArea51 - latest XML & CSSgt;nodeValue,
Utilities software for Windows</title>'date' =>
<link>(0)->nodeValue
<description>Try and buy latest XML &));
CSS Utilities software for Windows<}
description>?
<language>en-us</language>