<?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>Web Cash &#187; xml</title>
	<atom:link href="http://www.earn-web-cash.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Share Your Reading Habits: Google Reader</title>
		<link>http://www.earn-web-cash.com/2008/04/28/share-articles-google-reader/</link>
		<comments>http://www.earn-web-cash.com/2008/04/28/share-articles-google-reader/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 01:53:17 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Online Tools]]></category>
		<category><![CDATA[Redirected]]></category>
		<category><![CDATA[Blogs]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/04/28/share-articles-google-reader/</guid>
		<description><![CDATA[Part of developing a successful blog and your identity as a blogger is creating a web of blogs that you read and participate in. Imagine the blogosphere as a giant web. You want to connect your website to a bunch of others &#8211; you don&#8217;t want to just be a random thread connected to nothing. [...]]]></description>
			<content:encoded><![CDATA[<p>Part of developing a successful blog and your identity as a blogger is creating a web of blogs that you read and participate in.  Imagine the blogosphere as a giant web.  You want to connect your website to a bunch of others &#8211; you don&#8217;t want to just be a random thread connected to nothing.</p>
<p>Google Reader provides you with a nifty tool to help you do this.  With the &#8220;Share&#8221; feature of Google Reader, you can easily syndicate a list of articles that you recently read and found interesting.<br />
<span id="more-188"></span></p>
<h4>Get a Google Account: Start Reading</h4>
<p>If you don&#8217;t use Google Reader &#8211; or another feed reader &#8211; <strong>start</strong> using one.  Until you use RSS feeds on a daily basis, you&#8217;ll never know how wonderful they are, and you&#8217;ll never know how much your readers may come to rely on them.</p>
<p>Once I decide I like a site, I generally read it through Google Reader.  If an article is interesting, I&#8217;ll click through to the site and comment on it.  Other than that, I rarely go back to the site.  Without the RSS reader, I&#8217;d probably never return to the site at all.</p>
<p>An RSS reader is a great way to collect relevant readings into one location &#8211; so you can sit there with your cup of coffee and read all of the new stuff out in the blogosphere.  You can then decide what is important enough to comment on (on someone else&#8217;s blog) or respond to (on your own blog).</p>
<h4>Share Items &#8211; Creating Your Own Feed</h4>
<p>With Google Reader, there is a cool &#8220;Share&#8221; feature.  At the bottom of the article you are reading, there&#8217;s a list of options &#8211; &#8220;Add Star,&#8221; &#8220;Share,&#8221; &#8220;E-mail,&#8221; and &#8220;Mark as Read.&#8221;</p>
<p>By choosing the &#8220;Share&#8221; option you are adding that article to a publicly viewable list.  That list also generates its own RSS feed &#8211; which makes it easy for you to syndicate the feed on your own site.  By doing so, you provide your readers with a list of articles that you recently read and found interesting.</p>
<p>It&#8217;s a more targeted and stable than a standard RSS feed that just shows every headline from a given website &#8211; which will hopefully make it more useful for your readers.</p>
<h4>Grab the Widget, Style Yourself</h4>
<p>This feed is available in a standard rss xml file.  You could use <a href="http://www.earn-web-cash.com/2008/02/09/simple-xml-rss-feed/">SimpleXML to parse the feed</a> and display the information yourself.  Or, you could use the ready-made widget that Google provides.</p>
<p>The Google widget uses Javascript to access the information while your page is loading.  This potentially stops your page from hanging if the Google server is not responding &#8211; the rest of the page can load while the RSS feed is updated.  You can find this widget by clicking on the &#8220;Your shared items&#8221; link in Google Reader and clicking on the &#8220;put a clip of your shared items&#8221; link.</p>
<p>The only problem is that the pre-designed styles don&#8217;t offer you a lot of options for making the list blend in with your site&#8217;s theme.  My suggestion would be to select &#8220;None,&#8221; for the color scheme.  You may also want to leave the title blank, and add your own title to the feed.</p>
<p>If you do this, the feed will be generated with the following HTML.  Note:  This example uses the &#8220;Show item sources&#8221; option.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;readerpublishermodule0&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;reader-publisher-module&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Good for Hunters, Bad for Druids&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://4thehorde.wordpress.com/2008/04/25/good-for-hunters-bad-for-druids/&quot;</span>&gt;</span>Good for Hunters, Bad for Druids<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span>&gt;</span>from <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://4thehorde.wordpress.com&quot;</span>&gt;</span>For the Horde<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Bornakk: Druids Not to be &amp;quot;Big Green Blobs&amp;quot;&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://feeds.feedburner.com/%7Er/Resto4Life/%7E3/279629927/&quot;</span>&gt;</span>Bornakk: Druids Not to be &quot;Big Green Blobs&quot;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span>&gt;</span>from <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.resto4life.com&quot;</span>&gt;</span>Resto4Life<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;f&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.google.com/reader/shared/user/18391951200330501918/state/com.google/broadcast&quot;</span>&gt;</span>Read more...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>By taking a look at this example HTML, you can easily style the widget yourself.</p>
<p>The entire thing is contained in a div with class &#8220;reader-publisher-module.&#8221;  Each headline is contained within its own &#8220;li.&#8221;  If you use the option to display the source of the article, it&#8217;s in a div with class &#8220;s&#8221; inside the list item.</p>
<p>My one gripe with Google Reader is I can&#8217;t create multiple shared lists.  For example, I&#8217;ve divided blogs I read into ones related to web development and ones related to World of Warcraft.  I&#8217;d love to be able to create a shared article list for each topic, so that I can syndicate each one on a different website.</p>
<p>If you want to see this in action, check out my World of Warcraft blog, <a href="http://rolling-horde.net">Rolling Horde</a>.  It&#8217;s on the right hand side, in the middle column, underneath the recent articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/04/28/share-articles-google-reader/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tips to Ensure Your XML RSS Feed is Valid</title>
		<link>http://www.earn-web-cash.com/2008/03/15/valid-xml-rss-feed/</link>
		<comments>http://www.earn-web-cash.com/2008/03/15/valid-xml-rss-feed/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 14:01:06 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/15/valid-xml-rss-feed/</guid>
		<description><![CDATA[Last month, I wrote on article on creating an RSS feed for your site. Some people have reported problems with the process &#8211; but these all come from malformed XML, not the PHP code supplied in the article. There are a few things you need to keep in mind while writing an XML document, or [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, I wrote on article on <a href="http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/">creating an RSS feed for your site</a>.  Some people have reported problems with the process &#8211; but these all come from malformed XML, not the PHP code supplied in the article.</p>
<p>There are a few things you <strong>need</strong> to keep in mind while writing an XML document, or else the RSS reader will not be able to understand it.  It&#8217;s better to <a href="http://hsivonen.iki.fi/producing-xml/">think of writing XML as writing code than text</a>, because there are some strict syntax rules you need to adhere to.<br />
<span id="more-177"></span></p>
<h4>Balance Opening and Closing Tags</h4>
<p>One strict syntax rule of XML is that opening and closing tags must be balanced.  For every opening tag, there must be a closing tag.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In this example, the first item element is invalid &#8211; because description has no closing tag.  The second example is valid, because description is closed.  You could also use a self-closing tag if description doesn&#8217;t contain a value.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>With a simple feed, it can be easy enough to keep tags balanced.  However, it&#8217;s a good idea to look into <a href="http://www.earn-web-cash.com/2008/02/21/create-rss-feed-simplexml/">using an XML parser like SimpleXML to build the feed</a>.  This ensures that the tags are balanced and that the XML is well-formed.</p>
<h4>Ampersands Are Not Allowed</h4>
<p>The lovely ampersand &#8211; &amp; &#8211; is not allowed to appear in an XML document without being escaped (<code>&amp;amp;</code>).</p>
<p>If a browser or feed reader encounters an ampersand that isn&#8217;t escaped and that isn&#8217;t being used to form a valid entity, the application will simply stop reading.  You might overlook this possible problem if your URLs use query strings &#8211; and thus have ampersands inside them.</p>
<p>The solution is to escape all of the URLs and data that is going into your feed.  The reader will convert <code>&amp;amp;</code> back into &amp; so that your links work correctly.  PHP offers a function to help you do that.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$escapedText</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$unescapedText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pass all of the text that needs to be escaped (like your URLs) through the htmlentities function, and your problems will be solved.  Incidentally, this will also escape &gt; and &lt; characters.</p>
<h4>No Non-Breaking Spaces!</h4>
<p>The final tip deals with invalid entities, like <code>&amp;nbsp;</code>.  As mentioned before, ampersands are a strict no-no.  They can be used to form entity codes, but they cannot be used by themselves.</p>
<p>If you attempt to create an entity that the XML processor doesn&#8217;t recognize, it won&#8217;t read it as an entity &#8211; it will read it as an ampersand with some text following.  For example, <code>&amp;bob;</code> would be read by an XML processor as an ampersand and the word &#8220;bob;&#8221;.</p>
<p>It would then promptly stop processing your feed.</p>
<p>One common way for this to break your feed is the non-breaking space character &#8211; <code>&amp;nbsp;</code>.  These often serve no purpose in the document, but you might get them littered around your source code if you use a WYSIWYG editor.</p>
<p>You could get rid of these by filtering your output through a function that does a str_replace of <code>&amp;nbsp;</code> with &#8216; &#8216;.</p>
<p>If the non-breaking space character serves a purpose in your document, you can preserve it for the browser but make the XML processor ignore it.  This is where CDATA comes in.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[This is a description with content that</span>
<span style="color: #339933;">&lt;strong&gt;shouldn't&lt;/strong&gt; be interpeted</span>
<span style="color: #339933;">by the &amp;nbsp; XML processor.]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>When you wrap text inside that tag &#8211; <code>&lt;![CDATA[</code> and <code>]]&gt;</code> &#8211; you tell the processor to ignore the text and spit it out as is.  This can help your non-breaking space character make it to the user.  You may also want to use this if your descriptions and content include HTML tags.</p>
<h4>Browse the Spec</h4>
<p>These are a couple of tips to help you address some of the more common things that will break your XML documents.</p>
<p>However, there are many other minor errors you can come across.  The only way to learn about them and solve them is through two things &#8211; research and trial and error.</p>
<p>You may want to take some time to browse the <a href="http://www.xml.com/axml/testaxml.htm">XML specification</a> as well as read forums for problems that other people have.  Then, test things out and find out what doesn&#8217;t work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/15/valid-xml-rss-feed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RSS Feed: Building an RSS Data Feed in PHP with SimpleXML</title>
		<link>http://www.earn-web-cash.com/2008/02/21/create-rss-feed-simplexml/</link>
		<comments>http://www.earn-web-cash.com/2008/02/21/create-rss-feed-simplexml/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 01:48:07 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/21/create-rss-feed-simplexml/</guid>
		<description><![CDATA[RSS feeds are a must-have for modern websites. It&#8217;s easy enough to make an RSS feed of recent articles in PHP. But did you know an RSS feed can simply be information &#8211; not links to articles? This article will look at how to build a basic feed of data &#8211; for our purposes, we&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>RSS feeds are a must-have for modern websites.  It&#8217;s easy enough to <a href="http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/">make an RSS feed of recent articles in PHP</a>.  But did you know an RSS feed can simply be information &#8211; not links to articles?</p>
<p>This article will look at how to build a basic feed of data &#8211; for our purposes, we&#8217;ll consider random quotes.  It will also illustrate how to use SimpleXML to build the feed for us.<br />
<span id="more-145"></span></p>
<h5>The RSS 2.0 Standard</h5>
<p>RSS feeds, like XML in general, have specific standards.  In order to be use-able across platforms, it is imperative that standard syntax and naming patterns are used.  If you&#8217;re unfamiliar with the RSS 2.0 standard, you should look through a <a href="http://cyber.law.harvard.edu/rss/rss.html">copy here</a>.</p>
<p>Before we get to building the feed, let&#8217;s identify what tags we&#8217;re going to use.</p>
<p>The entire feed is wrapped in an <strong>&lt;rss&gt;</strong> tag.  Within that element is a <strong>&lt;channel&gt;</strong> element.</p>
<p>The <strong>&lt;channel&gt;</strong> element has a number of optional child elements.  The basic ones we&#8217;ll want to include are &#8211; <strong>&lt;title&gt;</strong>, <strong>&lt;description&gt;</strong>, <strong>&lt;link&gt;</strong>, and <strong>&lt;pubDate&gt;</strong>.</p>
<p>The actual data (our random quotes) is wrapped in <strong>&lt;item&gt;</strong> elements.  These also have a bunch of optional parameters.  We&#8217;ll be using the basics &#8211; <strong>&lttitle;&gt;</strong>, <strong>&lt;description&gt;</strong>, and <strong>&lt;pubDate&gt;</strong>.  Notice that there&#8217;s no link &#8211; because we&#8217;re feeding simple data, not articles!</p>
<h5>Creating the SimpleXML Object</h5>
<p>In order to create the SimpleXML object, you need to feed it some kind of XML string.  Normally this would be a completed file or string &#8211; like an existing feed.</p>
<p>Since we&#8217;re <strong>building</strong> the feed with SimpleXML, we don&#8217;t have a lot to start with.  We can give it a very basic string to create the object &#8211; an opening and closing <strong>rss</strong> element.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;rss version=&quot;2.0&quot;&gt;&lt;/rss&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Adding Child Elements</h5>
<p>The <code>addChild()</code> method of SimpleXML allows us to add child elements to existing elements.  In addition to adding a child element, the method returns a reference to the new child &#8211; allowing us to manipulate it in turn.</p>
<p>The first child we&#8217;ll need to create is the <strong>channel</strong> element.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$channel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'channel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That creates the <strong>channel</strong> element and stores a reference to it in $channel.  We can then use the $channel variable to add more children &#8211; the information defining the <strong>channel</strong> element itself.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Test Feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.earn-web-cash.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'This is a feed testing how to build an RSS feed in SimpleXML'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s T&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You may want to include other optional parameters that are included in the specification.  Just add another $channel->addChild() call with the parameter&#8217;s name and its value.</p>
<h5>Creating the Random Quote Items</h5>
<p>At this point, we just need to add our <strong>item</strong> elements and we&#8217;re done.  To do that, we&#8217;ll loop through an array of data, create an <strong>item</strong> element, and add the appropriate children to it.</p>
<p>Let&#8217;s assume that I retrieved information from a database table with three columns &#8211; title, description, and pubDate.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$newItem</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s T&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Again, you can add extra data to your feed by adding extra child elements.</p>
<h5>Outputting the Feed</h5>
<p>Now that the entire feed is stored in the $xml variable, we just need to output it.</p>
<p>In doing this, we&#8217;ll do two things.  We need to define the content-type as xhtml/xml.  Then we use the asXML() method to print the information in an xml string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/xhtml+xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You could alternatively save this to an xml file.  There are two ways to do this &#8211; either file_put_contents the output from asXML() or pass a filename as the parameter for asXML().</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//  or ...</span>
<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Start Feeding</h5>
<p>With this basic script, you can serve up any kind of information as an RSS feed.  This makes it easy for people to read it in their RSS readers or even access the information on the cell phones.</p>
<p>There are plenty of types of data you could use this for &#8211; quotes, jokes, question of the day, trivia, tip of the day, etc.  By publishing tiny bits of data on a daily basis, you keep your users coming back for more &#8211; but you don&#8217;t need to publish full size articles every day.</p>
<p>In case you ran into trouble putting the script together, here&#8217;s the entire source code with an array of data built into it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mark Twain on Profanity'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Under certain circumstances, profanity provides a relief denied even to prayer.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Woody Allen on People'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'It seemed the world was divided into good and bad people. The good ones slept better... while the bad ones seemed to enjoy the waking hours much more.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Will Rogers on Vets'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'The best doctor in the world is the veterinarian. He can\'t ask his patients what is the matter - he\'s got to just know.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Create the root element - RSS</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;rss version=&quot;2.0&quot;&gt;&lt;/rss&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Create the channel element, a child of RSS</span>
<span style="color: #000088;">$channel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'channel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Add random channel information</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Random Quotes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.earn-web-cash.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'This is a feed of random, interesting quotes.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s T&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Loop through and create item elements</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$newItem</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newItem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Output</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/xhtml+xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/21/create-rss-feed-simplexml/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Only Show the Digg Badge for Popular Posts</title>
		<link>http://www.earn-web-cash.com/2008/02/18/digg-badge-popular-posts/</link>
		<comments>http://www.earn-web-cash.com/2008/02/18/digg-badge-popular-posts/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 19:45:09 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Online Tools]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/18/digg-badge-popular-posts/</guid>
		<description><![CDATA[Digg can be a great source of traffic and recognition for tech related blogs. Some people take it to the extreme though, and show the &#8220;Digg This&#8221; badge on every article they write. As others have pointed out, this can be counter-productive. People don&#8217;t like to read articles that have just one Digg &#8211; they [...]]]></description>
			<content:encoded><![CDATA[<p>Digg can be a great source of traffic and recognition for tech related blogs.  Some people take it to the extreme though, and show the &#8220;Digg This&#8221; badge on every article they write.</p>
<p>As <a href="http://www.pronetadvertising.com/articles/why-the-digg-button-gets-you-buried-not-dugg11995.html">others have pointed out</a>, this can be counter-productive.  People don&#8217;t like to read articles that have just one Digg &#8211; they seem unpopular.</p>
<p>So here&#8217;s a solution: use the <a href="http://www.earn-web-cash.com/scripts-plugins-and-modules/wp-plugin-digg-badge/">Conditional &#8220;Digg This&#8221; WordPress Plugin</a> to only show the Digg Badge for articles that have a certain number of Diggs.<br />
<span id="more-129"></span></p>
<h5>Why Shouldn&#8217;t You Show the Digg Badge on Every Article?</h5>
<p>It&#8217;s easy enough to plaster the Digg Badge in your template or use a plug-in to add it to every post.  Most of your posts aren&#8217;t going to be popular though.  You&#8217;ll get at most one or two Diggs&#8230; nothing to write home about.</p>
<p>When a user opens your article, he or she might be impressed by &#8220;100 Diggs.&#8221;  He or she definitely won&#8217;t be impressed by &#8220;1 Digg.&#8221;  That&#8217;s a hint that your article wasn&#8217;t anything special &#8211; so why should the reader keep going?</p>
<h5>Using the Plugin to Only Show the Badge on Popular Articles</h5>
<p>The <a href="http://www.earn-web-cash.com/scripts-plugins-and-modules/wp-plugin-digg-badge/">Conditional Digg This</a> plug-in was designed to address this issue.</p>
<p>All you need to do is download the source code, upload it to your plugins directory, unpack the tar.gz, and click &#8220;Activate.&#8221;  You don&#8217;t need to modify any settings or insert anything into your template.  It&#8217;s all automated.</p>
<h5>How Does It Work?</h5>
<p>The basic concept behind the plugin is this:</p>
<ul>
<li>Load a story in your WordPress Blog</li>
<li>Check the Digg API to see how many diggs the article has</li>
<li>If the article has 10 or more diggs, show the badge&#8230;</li>
<li>Otherwise, leave it alone.</li>
</ul>
<p>Originally, I coded the plug-in to use a php function to access the API and check the number of Diggs each article had as it loaded.  This worked perfectly &#8211; but it took a while.  Sometimes, the API is slow to respond.  If the API took 8 seconds to spit back a response, that meant your page would take 8 extra seconds to load up.</p>
<p>Even if the API was responding quickly, this was a problem for the front page and category pages.  At best, the API takes about .25 to .5 seconds to respond &#8211; and with 10-15 checks on a page&#8230; you&#8217;re still waiting a good long time for the page to load.</p>
<h5>Load First, Check the API Later</h5>
<p>The solution I came up with was to use some nifty AJAX to perform the API checking behind the scenes.</p>
<p>The plug-in creates an AJAX request for each article.  It sends information to a php script which accesses the Digg API behind the scenes.  The page loads up instantly and AJAX will quietly do its thing.  When the response is ready, it&#8217;ll change the page to include the Digg This badge if necessary.</p>
<p>So, the next time you want to display a &#8220;Digg This&#8221; badge on your article, think about how many diggs your article has already.  Or, use the <a href="http://www.earn-web-cash.com/scripts-plugins-and-modules/wp-plugin-digg-badge/">Conditional &#8220;Digg This&#8221; WordPress Plugin</a> to automatically add a badge to your popular articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/18/digg-badge-popular-posts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Digg API: Grabbing a Random Digg Story with PHP</title>
		<link>http://www.earn-web-cash.com/2008/02/16/digg-api-random-story/</link>
		<comments>http://www.earn-web-cash.com/2008/02/16/digg-api-random-story/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 00:46:22 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Online Tools]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/16/digg-api-random-story/</guid>
		<description><![CDATA[I read about the Digg API the other day, and I thought it was about time I played around with it. There is a ton of cool stuff you can do with this. Basically, you send a request to the Digg server and it sends back whatever kind of information you want &#8211; category names, [...]]]></description>
			<content:encoded><![CDATA[<p>I read about the <a href="http://apidoc.digg.com/">Digg API</a> the other day, and I thought it was about time I played around with it.</p>
<p>There is a ton of cool stuff you can do with this.  Basically, you send a request to the Digg server and it sends back whatever kind of information you want &#8211; category names, recent diggs, recent stories, archived stories, etc.  You can read through the API to see everything you can do.</p>
<p>For now, we&#8217;ll focus on one nifty little trick &#8211; grabbing a random story from a given topic.<br />
<span id="more-122"></span></p>
<h5>Digg API Basics: How It Works</h5>
<p>Before we can build our script, we need to know the basics of how the Digg API works.</p>
<p>Your script sends an HTTP GET request to the Digg server.  This has three major parts.  If this is valid, the server sends you a response in one of several designated formats.  You can then parse it into use-able information and display it on your site.</p>
<p>The basic parts of the request are&#8230;</p>
<ul>
<li>Base Digg URL: http://services.digg.com</li>
<li>An <strong>Endpoint</strong>: i.e. /stories/topic/programming &#8211; this determines the type of information you&#8217;re getting back</li>
<li>A <strong>query string</strong>: i.e. ?count=5&#038;offset=20</li>
</ul>
<p>For this tutorial, we&#8217;ll be working with the &#8220;Programming&#8221; topic because, well, it works with my site.  You can look at the list of topics on the API page and tailor this to your needs.</p>
<p>Therefore the URL we&#8217;ll be accessing is: http://services.digg.com/stories/topic/programming</p>
<h5>What Goes In the Query String</h5>
<p>To go along with this, we&#8217;re going to have to build a query string.  There are a few required elements (appkey, type) and some optional ones that we&#8217;ll also use (count, offset).</p>
<p>&#8220;appkey&#8221; is basically an ID tag associated with your application.  Digg uses this for statistical purposes.  You can set this equal to the URI of your website.</p>
<p>&#8220;type&#8221; describes the type of response you&#8217;ll get.  There are four response types, of which two are applicable for use in a PHP script.  We&#8217;re going to focus on the XML response and use SimpleXML to parse the information.  Therefore type should be set to &#8216;xml.&#8217;</p>
<p>&#8220;count&#8221; tells the server how many stories we want to fetch.  &#8220;offset&#8221; tells the server how many stories to skip before it starts fetching them.  The &#8220;offset&#8221; is going to allow us to fetch a random story.</p>
<h5>Building the Query String</h5>
<p>So how do we build the query string?  First, we need to turn each of our values into a parameter in the format <code>key=value</code>.  The value must also be url encoded.  Here&#8217;s how we do that in php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$appkey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.earn-web-cash.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appkeyParam</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'appkey='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appkey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can then string together all these variables with ampersands (&#038;) in between.  We then place a ? in the beginning of the query string, attach it to our URL, and we&#8217;re good to go.</p>
<p>I wrote a short function I use to automatically build the query string from an array of values.  I create an empty array, store the value with a key equal to its parameter name, and then pass it through the function.  The function returns the full query string for me to use.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Example array:</span>
<span style="color: #666666; font-style: italic;">//    $params['appkey'] = 'http://www.earn-web-cash.com';</span>
<span style="color: #666666; font-style: italic;">//    $params['type'] = 'xml';</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> buildQuery <span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'?'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'?'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>One other minor task we need to do is set up a &#8220;user_agent&#8221; for PHP.  The Digg server wants to know who&#8217;s accessing it, so you need to define a &#8220;user_agent&#8221; value for your instance of PHP with the ini_set command.  You can call your application whatever you want, but it usually follows the format &#8211; Name/Version.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_agent'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'RandomDiggStory/1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Firing Off the Request and Getting a Response</h5>
<p>We should now be able to send our request, get a response, and use some information.</p>
<p>To get a random story, we&#8217;re actually going to have to send two requests.  The first is going to allow us to find out how many stories exist in the topic.  The second will actually fetch a random story.</p>
<p>To find out how many stories exist in the topic, we&#8217;re going to create our request with the following information.  The appkey doesn&#8217;t matter, the type will be xml, the count will be 0, and the offset doesn&#8217;t matter.</p>
<p>Once we build the entire url with the query string, we open that location with simplexml_load_file &#8211; and the response will automatically be placed in a SimpleXML object for us.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'appkey'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.earn-web-cash.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xml'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//  We don't need an offset for this one</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> buildQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://services.digg.com/stories/topic/programming'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$reqUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$url</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reqUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$xml</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Need to typecast, or it'll be an object</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Look at the source code to see what you fetched</span></pre></div></div>

<p>The last line (echo $xml->asXML()) isn&#8217;t necessary &#8211; it&#8217;s just to give you an idea of the information you just fetched.  It isn&#8217;t a whole lot &#8211; but we didn&#8217;t ask for a whole lot.</p>
<p>The piece of information we wanted was the total number of stories in our topic.  That&#8217;s the &#8216;total&#8217; attribute of the &#8216;stories&#8217; element.  We fetched it with <code>$xml['total']</code> and stored it in the $total variable.</p>
<h5>Last Step: Fetching the Random Story</h5>
<p>With this information in hand, we can craft a new request and get our random story.  You can copy and paste the same information we used before, but make these changes to the <code>$params</code> array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// We want one story</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$total</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By generating a random value for offset between 0 and the maximum, we&#8217;re effectively choosing one random story from the available list.</p>
<p>Now run the script again.  At the end, $xml should have one random story stored in it.  The story information is stored in the <code>story</code> child element, and we can access some of the information like this.</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;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">story</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the URL</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">story</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit_date'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// timestamp when it was submitted</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">story</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;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you browse through the source code of the xml you outputted, you&#8217;ll find all of the essential information about the story.  Now you can format it nicely and add it to your website.</p>
<p>In case you ran into trouble along the way, here&#8217;s the complete <a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/random-digg-article.txt' title='Random Digg Article Script'>source code</a> of the script.  You&#8217;ll need to go in and change the topic to your desired topic and set your own appkey, but otherwise it should be all set to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/16/digg-api-random-story/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>How to Access XML Attributes in PHP Using SimpleXML</title>
		<link>http://www.earn-web-cash.com/2008/02/15/xml-attributes-php/</link>
		<comments>http://www.earn-web-cash.com/2008/02/15/xml-attributes-php/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 19:29:49 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/15/xml-attributes-php/</guid>
		<description><![CDATA[A user on Programming Talk had a problem the other day.  He was trying to build an XML parser to work with an xml data file (a character sheet from the WoW Armory).

His parser wasn't working - because all of the information was stored in attributes instead of child elements.  What's the difference between the two?  And how can we fix it?

Use SimpleXML.]]></description>
			<content:encoded><![CDATA[<p>A user on Programming Talk had a problem the other day.  He was trying to build an XML parser to work with an xml data file (a character sheet from the WoW Armory).</p>
<p>His parser wasn&#8217;t working &#8211; because all of the information was stored in attributes instead of child elements.  What&#8217;s the difference between the two?  And how can we fix it?</p>
<p>Use SimpleXML.<br />
<span id="more-114"></span></p>
<h5>Difference Between a Child and an Attribute</h5>
<p>For starters, let&#8217;s take a look at a sample XML file.  This will help illustrate the difference between a child element and an attribute, and it will give us something to work with later on.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;library<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>John Steinback<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Of Mice and Men<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>F. Scott Fitzgerald<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Great Gatsby<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/library<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This simple XML file is a &#8220;library.&#8221;  It contains a list of books &#8211; each of which has an author, a title, and a &#8220;lang&#8221; attribute.</p>
<p>In this example, &#8220;book&#8221; is an element.  It is a <strong>child</strong> element of library &#8211; which means it is an element created <strong>inside</strong> the open library element.  You could also refer to the library element as the <strong>parent</strong> of all the book elements.</p>
<p>To create a child element, you simply create a set of tags within a larger set of tags.  The book is a child of library, while the author is a child of book.  We could create more children for &#8220;Author&#8221; &#8211; like age, sex, and hair color.</p>
<p>By contrast, &#8220;lang&#8221; is an attribute.  It is defined inside the opening tag of an element.  By declaring <code>lang="en"</code> we are saying that the book has the attribute of being written in English.</p>
<p>It is simply another (perhaps more annoying) way to store information in an XML file.  Most basic XML parsers look for tags and content &#8211; but the attribute is neither.  It&#8217;s contained inside a tag, so it needs to be handled specially.  </p>
<p>Thankfully, SimpleXML is designed to help us do just that.</p>
<h5>Loading the File in SimpleXML</h5>
<p>I saved the xml file above in &#8220;xmltest.xml.&#8221;  In my php script, I can load it into a SimpleXML object with this function call.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xmltest.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This creates a SimpleXML object which is a tree of connected objects.  The root object represents the &#8220;library&#8221; element.  It then has an array of children called &#8220;book,&#8221; and each &#8220;book&#8221; element has two children element of its own.</p>
<p>Using the SimpleXML object structure, we can access some pieces of our XML document like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">book</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//  All of the info in Book 1</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">book</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;">author</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// First book, John Steinbeck</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">book</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</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: #666666; font-style: italic;">// Second book, The Great Gatsby</span></pre></div></div>

<h5>Accessing the Lang Attribute in the Object Tree</h5>
<p>The initial question now resurfaces &#8211; how do we access an attribute, like the &#8216;lang&#8217; attribute?</p>
<p>All of the elements are nicely arranged in a tree.  The parent element has a child element, which has a child element, so on and so forth.  We can easily access these as related objects like we did above.</p>
<p>The attributes are exploded into an array and attached to the element that they define.  So, for example, we defined a &#8216;lang&#8217; attribute for our book element.  Therefore, the value of lang will reside in an array attached to that specific book element.</p>
<p>We can access it like this.</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;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">book</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// en</span></pre></div></div>

<p>To find an attribute of an object with SimpleXML, you navigate to the element in question and then access an array indexed by the names of the attributes.  In this case, our attribute was named &#8216;lang&#8217; so we use &#8216;lang&#8217; as a key in the array to get the value.</p>
<p>For simplicity&#8217;s sake, it is usually better to define all of your XML data as child elements.  This allows you to easily expand data types in the future, and you won&#8217;t have to mix methods for accessing the data.</p>
<p>However, if you&#8217;re working with someone else&#8217;s XML file, you may need to look up attributes.  Now you know how.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/15/xml-attributes-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to Create an RSS Feed for Your Site in PHP</title>
		<link>http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/</link>
		<comments>http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 23:31:48 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/</guid>
		<description><![CDATA[Most blogging platforms come with built-in support for RSS feeds.  Why?  It's a great way for users to keep up to date on your new content.  Instead of loading up a dozen favorite sites, they can look at one feed reader and then decide what to pursue further.

So what if you don't use a blogging platform or CMS that creates a feed for you?  You can create one yourself in PHP.  It's pretty simple.]]></description>
			<content:encoded><![CDATA[<p><a href="http://life-of-brian.com/?attachment_id=614"><img class="alignright" title="Globe and Keyboard" src="http://life-of-brian.com/wp-content/uploads/2008/12/1097852_95279728-300x199.jpg" alt="Picture of a globe in front of a keyboard." /></a>Note: If you look around the site, you may have noticed that I haven&#8217;t updated this place in a long time. Check out my new project, which is more closely focused on <a href="http://digital-photography-howto.com">photography</a>. I still discuss some design issues, though, like these <a href="http://digital-photography-howto.com/free-indesign-templates/">free InDesign templates</a>. If you&#8217;re looking for a camera, check out this post on the <a href="http://digital-photography-howto.com/canon-t1i-to-t2i-to-t3i-what-digital-slr-camera-to-buy/">differences between entry level Canon dSLR cameras</a>.</p>
<p>Or, take a look at my <a href="http://olinda-gibbons.com">photography studio&#8217;s website</a>. Along with photography, we offer a handful of <a href="http://olinda-gibbons.com/print/">design and printing services</a>, mostly for models, actors, and fashion designers. Our newest offering is the <a href="http://olinda-gibbons.com/print/info-on-comp-zed-cards/">design and printing of modeling/acting comp cards</a>, which start at $60 for a set.</p>
<p>Most blogging platforms come with built-in support for RSS feeds.  Why?  It&#8217;s a great way for users to keep up to date on your new content.  Instead of loading up a dozen favorite sites, they can look at one feed reader and then decide what to pursue further.</p>
<p>So what if you don&#8217;t use a blogging platform or CMS that creates a feed for you?  You can create one yourself in PHP.  It&#8217;s pretty simple.<br />
<span id="more-112"></span></p>
<h5>Elements of an RSS 2.0 Feed</h5>
<p>There are pretty strict standards about RSS feeds &#8211; intended to make it easier for readers to parse and display the information.  Before we dive into building a feed, we should look at what it should contain.  You can read the <a href="http://feedvalidator.org/docs/rss2.html" title="RSS Feed 2.0 Specification">full spec at feedvalidator</a>.</p>
<p>An RSS 2.0 Feed is a special type of XML file.  The first things you&#8217;ll need in your file is an xml declaration, and an opening/closing RSS tag.  Like this.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  //  Feed elements here
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Inside the opening rss tag, you can also include any <a href="http://validator.w3.org/feed/docs/howto/declare_namespaces.html">namespaces</a> that you&#8217;ll be using.  That&#8217;s a bit more than we need to worry about at the moment, though.</p>
<p>Inside the rss tag, you need to create a channel tag.  This holds all of the individual articles as well as some basic information about the feed.  You&#8217;re required to create a <strong>title</strong>, <strong>link</strong>, and <strong>description</strong> tag.  You can add a lot of optional tags, of which the <strong>lastBuildDate</strong> tag would be most useful.</p>
<p>A basic channel declaration would look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Wonderful Blog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://mydomain.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This is a feed of the latest articles at My Wonderful Blog.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Thu, 14 Feb 2008 10:57:05 GMT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
   //  Include individual articles here
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally, you can include the individual articles inside of this channel tag.  Each article is represented by an item tag and a series of optional tags.  Some good tags to use for a basic feed would be <strong>title</strong>, <strong>link</strong>, <strong>description</strong>, and <strong>pubDate</strong>.  Like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Latest Article<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://mydomain.com/latestarticle.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This is the latest cool article at my wonderful blog.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Thu, 14 Feb 2008 10:57:05 GMT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h5>Using PHP to Create the RSS Feed</h5>
<p>Now that we know what goes <strong>in to</strong> an RSS feed, we can worry about how to <strong>create</strong> one.</p>
<p>There are several approaches we can take here.  We could have PHP dynamically output an RSS feed every time the file is accessed.  We could create a SimpleXML object and write it to a file each time a new article is added.  Or we could simply create a string and write it to an xml file.</p>
<p>We&#8217;ll take the third approach.  This means we need to do three things.</p>
<ul>
<li>Fetch the data from the database</li>
<li>Build the xml formatted string</li>
<li>Write the xml data to a file</li>
</ul>
<h5>Fetch the Data from the Database</h5>
<p>This will vary depending on the database type you&#8217;re using and how it&#8217;s set up.  If you&#8217;ve gotten this far in creating a dynamic, PHP-driven site, I&#8217;m sure you can figure out how to fetch information for your own database.</p>
<p>For the purpose of this tutorial, we&#8217;ll fetch information from a mySQL database.  The database will hold the title, link, description, and pubDate of each article.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT title, link, description, pubDate FROM
   articles LIMIT 10&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note:  I only retrieved the last 10 entries.  There is no strict limit to the number of entries an RSS 2.0 feed can have, but it&#8217;s polite to leave it small.  If they want to read every article, they&#8217;ll come to your site.</p>
<h5>Building the XML Formatted String</h5>
<p>Now, we need to create a blank string, format it like an XML file, loop through the mySQL result array, and insert the data into the XML file.</p>
<p>First, we&#8217;ll add the xml declaration, the rss tag, the channel tag, and the channel info.  Then we can loop through the result set and create one item tag for each article.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">$xmlString = '<span style="color: #000000; font-weight: bold;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;rss version=&quot;2.0&quot;&gt;
&lt;channel&gt;
   &lt;title&gt;My Wonderful Blog&lt;/title&gt;
   &lt;link&gt;http://mydomain.com/&lt;/link&gt;
   &lt;description&gt;Latest articles at My Wonderful Blog.&lt;/description&gt;
   &lt;lastBuildDate&gt;' . date(&quot;D, d M Y H:i:s e&quot;) . '&lt;/lastBuildDate&gt;
&nbsp;
';
&nbsp;
while ($row = mysql_fetch_array($result)) {
$xmlString .= '   &lt;item&gt;
      &lt;title&gt;' . $row['title'] . '&lt;/title&gt;
      &lt;link&gt;' . $row['link'] . '&lt;/link&gt;
      &lt;description&gt;' . $row['description'] . '&lt;/description&gt;
      &lt;pubDate&gt;' . date(&quot;D, d M Y H:i:s e&quot;, $row['pubDate'] . '&lt;/pubDate&gt;
   &lt;/item&gt;
';
}
&nbsp;
$xmlString .= '&lt;/channel&gt;
&lt;/rss&gt;';</pre></div></div>

<p>Most of that should be self-explanatory.  Where I added a newline before ending the string, I was simply adding white space to make the source code more readable.  This isn&#8217;t necessary &#8211; but I like neat, readable source code.</p>
<p>$xmlString is being created in the beginning.  Then, the additional strings are appended to it with the .= operator.</p>
<p>The one important thing to note here is <code>date("D, d M Y H:i:s e")</code>.  This is PHP&#8217;s function to create a formatted date.  The characters inside the string determine how the timestamp is formatted.</p>
<p>This format is the standard required by RSS 2.0 feeds.  You could simply copy and paste this string to format your dates.  &#8220;D, d M Y&#8221; creates something like &#8220;Thu, 14 Feb 2008.&#8221;  &#8220;H:i:s&#8221; creates the time as &#8220;18:23:30.&#8221;  &#8220;e&#8221; is a representation of the timezone &#8211; which should be GMT.</p>
<h5>Write the String to an XML File</h5>
<p>Finally, we need to write this string to an xml file.  For simplicity&#8217;s sake, we&#8217;ll call this &#8220;feed.xml&#8221; and place it in the same directory as our script.</p>
<p>You could use a few functions to do the file-writing.  In this case, <code>file_put_contents</code> would be simplest &#8211; all we need to do is dump the contents of the string into a file and overwrite any previous contents.</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;feed.xml&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$xmlString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you just need to incorporate this into your existing site.  You could make this a standalone script and access it every time you add new content to your site.</p>
<p>Or, if you&#8217;re using some kind of home-brewed CMS, you could wrap this in a function and call it right after you save the content of a new article.</p>
<p>Besides creating a custom feed for your own website, there are some other uses for this.  You could use it to create a feed of articles from diverse sources around the internet.</p>
<p>If you write at a variety of sites &#8211; like Helium, Associated Content, and Xomba &#8211; you can use this to create a unified feed.  Or, you could create a feed of only <strong>select</strong> articles from one of those sources.  You could also create a feed of simple data &#8211; not articles &#8211; like quotes, jokes, tips, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/14/create-rss-feed-php/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>How to Integrate an RSS Feed Into Your Site with Simple XML</title>
		<link>http://www.earn-web-cash.com/2008/02/09/simple-xml-rss-feed/</link>
		<comments>http://www.earn-web-cash.com/2008/02/09/simple-xml-rss-feed/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 23:53:58 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/09/simple-xml-rss-feed/</guid>
		<description><![CDATA[Practically every site today has an RSS feed. Now, you could be like everyone else and simply use this as a way to read information as it&#8217;s published. Or, you could use RSS for what&#8217;s intended for &#8211; content syndication. With Simple XML, it&#8217;s a piece of cake to use an RSS feed to add [...]]]></description>
			<content:encoded><![CDATA[<p>Practically every site today has an RSS feed.  Now, you could be like everyone else and simply use this as a way to read information as it&#8217;s published.</p>
<p>Or, you could use RSS for what&#8217;s intended for &#8211; content syndication.  With Simple XML, it&#8217;s a piece of cake to use an RSS feed to add a list of links to relevant articles on your page.<br />
<span id="more-105"></span></p>
<h5>What Are RSS Feeds and XML Files?</h5>
<p>Hopefully you know what an XML file and an RSS feed is.  If not, here&#8217;s the quick and dirty explanation.</p>
<p>An XML file is a special way to store information.  All of the information is wrapped in tags &#8211; kind of like HTML.  However, instead of using this to format the output, this is used to tell the reader what the information means.</p>
<p>So, for example, a <code>&lt;link&gt;</code> tag would probably describe a link.</p>
<p>XML was created to allow information to be easily ported between platforms and systems.  An RSS feed is a special type of XML file to help reach that goal.  Most websites (including almost all blogs), publish an RSS feed that is simply an XML file containing the latest few entries on the website.</p>
<p>An RSS feed also has a standard structure &#8211; which is why we can easily build a script that can parse <strong>any</strong> valid RSS feed and add the links to your site.</p>
<h5>Getting Started with Simple XML</h5>
<p>Before SimpleXML, you had to build your own XML parser to work with PHP and XML files.  This was possible, but it meant a lot of overhead &#8211; so it wasn&#8217;t a good idea for small projects.</p>
<p>With SimpleXML, you can load any XML file into PHP as a specially structured object.  The object&#8217;s structure mirrors the XML file.  So, if there&#8217;s a <code>&lt;item&gt;</code> tag, it creates an object with name &#8220;item.&#8221;  It then creates children objects of every tag <strong>inside</strong> that item tag.</p>
<p>To load an XML file into a SimpleXML object, you simply use this function call.  Run this entire script to see what the SimpleXML object looks like after it&#8217;s loaded.</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.dzone.com/links/feed/frontpage/rss.xml&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//  That's the DZone RSS Feed</span>
&nbsp;
<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>

<h5>What&#8217;s In an RSS Feed, and How Do We Use It?</h5>
<p>If you ran that script, you should see the guts of an RSS feed.  I&#8217;d suggest you view the source code of the output page, since it&#8217;ll be formatted nicely for you.</p>
<p>Like I mentioned before, RSS feeds have a standard structure so that apps can predictably interact with them.  This is the basic structure you should see inside the DZone RSS feed.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">//  Some random stuff up top
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  // This parent tag holds all the page information
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  //  There's one item per page listed in the feed
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ... <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ... <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ... <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ... <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  //  You could have a lot more <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> tags here
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>All of this information is nicely placed in our SimpleXML object for us to manipulate.</p>
<p>The entire channel (all of the children tags inside the channel tag) is stored in the &#8216;channel&#8217; object, which is a child of the larger &#8216;feed&#8217; object that we created earlier ($feed).</p>
<p>You can access the channel like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If there were multiple channels, then &#8216;channel&#8217; wouldn&#8217;t be a single object &#8211; it would be an array of objects.  This is the case with the &#8216;item&#8217; tags.  There are a lot of items, so they are stored in an array &#8211; which is a child object of the &#8216;channel.&#8217;</p>
<p>You can access the items like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span> <span style="color: #009900;">&#40;</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>n<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, the individual item holds most of the information we want.  It has children named &#8216;pubDate,&#8217; &#8216;title,&#8217; and &#8216;link&#8217; (along with a few other optional parameters).</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>

<h5>So How Is This Useful to Us?</h5>
<p>As you may have noticed, each item consists of the information you need to make a link back to it.  The item consists of a title, a URL, a pubDate, and a description.  You could use any combination of these that you feel is useful &#8211; but here&#8217;s an example of how to create a link to an article.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</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: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</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: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s all there is to it.  You could spruce it up by adding a date underneath the link.  Or you could add a short excerpt of the description.</p>
<h5>What If I Want to Include All of the Links?</h5>
<p>I suppose adding one link is kind of silly.  With a loop, we can easily iterate through the item[] array and output a link for every item in the RSS feed.</p>
<p>For good measure, we&#8217;ll also format it nicely in an unordered list.  From there, you can add some styling and it&#8217;ll fit right into the sidebar of your page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//  Load the XML file into a Simple XML object</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.dzone.com/links/feed/frontpage/rss.xml&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>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Iterate through the list and create the ul</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</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: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a href='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;&quot;</span> <span style="color: #339933;">.</span>
    <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There ya have it.  A semantically structured list, built from a remote RSS feed.  All in a couple lines of code.</p>
<p>You could of course separate this out into a function, and then pass a filename (and perhaps a limiting # of items to print) to your function.  The function would return a string with the html list, or output it directly (depending on your preference).</p>
<p><strong>Word of Caution:</strong>  Remember that you don&#8217;t own content just because it is published in an RSS feed.  The author still does.</p>
<p>I would assume that it&#8217;s fair game and free of copyright issues to print links to the original author&#8217;s site.  However, some authors publish their entire articles in their RSS feeds.  <strong>Do not</strong> re-publish the entire article.  That is copyright infringement, it is illegal, and you can get in a lot of trouble.  Not to mention it&#8217;s highly unethical.</p>
<p>With that in mind, happy syndicating!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/09/simple-xml-rss-feed/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

