<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Software Developing &#187; feeds</title>
	<atom:link href="http://www.phpdeveloping.co.za/tag/feeds/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RSS feeds made simple with SimpleXML</title>
		<link>http://www.phpdeveloping.co.za/rss/rss-feeds-made-simple-with-simplexml.html</link>
		<comments>http://www.phpdeveloping.co.za/rss/rss-feeds-made-simple-with-simplexml.html#comments</comments>
		<pubDate>Thu, 23 Jul 2009 06:09:11 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[RSS]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=45</guid>
		<description><![CDATA[Getting RSS and XML to work seems to always be a pain, at least that is how it was when I started working with it.  All changed when SimpleXML was introduced.  Up until I learned about SimpleXML, I always used my own little script that converted a XML feed into a associative array.
With [...]]]></description>
			<content:encoded><![CDATA[<p>Getting RSS and XML to work seems to always be a pain, at least that is how it was when I started working with it.  All changed when <a target=_blank href="http://www.php.net/simplexml">SimpleXML</a> was introduced.  Up until I learned about SimpleXML, I always used my own little script that converted a XML feed into a associative array.</p>
<p>With SimpleXML though, it&#8217;s a lot simpler to work with feeds.</p>
<p>All you need is the following lines of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.phpdeveloping.co.za/feed&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From here you will see $feed containing all the information you can get from the feed, all neatly structured into an array.</p>
<p>You access the various items through:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span>n<span style="color: #009900;">&#93;</span></pre></div></div>

<p>As an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can now iterate through all the items doing whatever you want to the data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/rss/rss-feeds-made-simple-with-simplexml.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
