<?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; tutorial</title>
	<atom:link href="http://www.earn-web-cash.com/tag/tutorial/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>Use Javascript to Parse a Query String</title>
		<link>http://www.earn-web-cash.com/2008/03/04/use-javascript-to-parse-a-query-string/</link>
		<comments>http://www.earn-web-cash.com/2008/03/04/use-javascript-to-parse-a-query-string/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 04:19:33 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[JS Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/04/use-javascript-to-parse-a-query-string/</guid>
		<description><![CDATA[Most server-side scripting languages, like PHP, come with built-in functionality for reading query strings. Javascript doesn&#8217;t have any kind of standard counterpart, but that doesn&#8217;t mean you can&#8217;t use query strings in Javascript. With some String functions, you can create your own function to parse a query string attached to the request url and store [...]]]></description>
			<content:encoded><![CDATA[<p>Most server-side scripting languages, like PHP, come with built-in functionality for reading query strings.  Javascript doesn&#8217;t have any kind of standard counterpart, but that doesn&#8217;t mean you can&#8217;t use query strings in Javascript.</p>
<p>With some String functions, you can create your own function to parse a query string attached to the request url and store it in an associative array &#8211; just like PHP would for you.<br />
<span id="more-171"></span></p>
<h4>What Are Query Strings For</h4>
<p>If you&#8217;re developing anything more than a basic informative page, you&#8217;ll need to pass information from one page to the next.  You might want to pass a search query, some form values, the answer to a quiz question, or any number of other things.  Passing this information is the first step in converting your page from a static bit of information into a dynamic application.</p>
<p>One way to pass information between pages is to use a query string.  That&#8217;s the long line of text after the &#8216;?&#8217; in a URL.  Kind of like this.</p>
<pre>http://www.google.com/search?hl=en&#038;q=widgets&#038;btnG=Google+Search</pre>
<p>That&#8217;s a standard query string attached to a Google search.  It sends a few values to the new page &#8211; hl (en), q (widgets), and btn (Google Search).  These values are then used to determine what is displayed on the new page.</p>
<p>In PHP, these values are automatically stored in an associative array &#8211; the $_GET array.  To make these values easily available to our Javascript code, we can write a function to do the same thing.</p>
<h4>The Structure of a Query String</h4>
<p>In order to break a query string down, we need to understand the rules for building one.</p>
<p>A query string always starts with &#8216;?&#8217;.  This separates the query string from the actual URL.</p>
<p>This is followed by key-value pairs, like &#8220;key=value&#8221;.  If there is more than one key-value pair, they are separated by an ampersand &#8211; &#8220;key1=value1&amp;key2=value2&#8243;.</p>
<p>Finally, these values are url_encoded.  Special characters &#8211; like spaces, ampersands, and equal signs &#8211; are converted to code so that they don&#8217;t interfere with the URL or the query string.</p>
<h4>Step One: Get the Request String and Separate the Query</h4>
<p>The first thing we need to do is get the entire request string and separate out just the query string.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//  Fetch the entire request string</span>
<span style="color: #003366; font-weight: bold;">var</span> href <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> hrefParts <span style="color: #339933;">=</span> href.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//  [0] is the URL, [1] is the query string</span>
<span style="color: #003366; font-weight: bold;">var</span> query <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span>hrefParts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The request string is accessible through the window.location object.  We use the split method of the string class to explode it at the &#8216;?&#8217;.  This leaves us with two parts, and we save the entire query string in the variable <code>query</code>.</p>
<h4>Step Two: Get the Key Value Pairs</h4>
<p>At this point, our query string in the variable <code>query</code> might look something like this:</p>
<pre>hl=en&#038;q=widgets&#038;btnG=Google+Search</pre>
<p>To get the key-value pairs, we can use another split() call.  This time, we split the string at each ampersand (&amp;).  The resulting array will contain the strings &#8220;hl=en&#8221;, &#8220;q=widgets&#8221;, and &#8220;btnG=Google+Search&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> valuePairs <span style="color: #339933;">=</span> query.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Step Three: Loop Through and Create an Array</h4>
<p>Now we can loop through the array valuePairs, split each pair, and create a new array where each value is indexed by its key.  This gives us a nicely indexed array just like PHP would.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> getArray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">for</span> each <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> pair <span style="color: #000066; font-weight: bold;">in</span> valuePairs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// [0] = key, [1] = value</span>
  <span style="color: #003366; font-weight: bold;">var</span> tempPair <span style="color: #339933;">=</span> pair.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Unescape converts the text back from URL encoding</span>
  getArray<span style="color: #009900;">&#91;</span>tempPair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> unescape<span style="color: #009900;">&#40;</span>tempPair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At this point, getArray[] should hold all of the values in our query string.</p>
<h4>Why Bother?</h4>
<p>Good question.  If PHP (and other server side scripts) automatically parse query strings, why should we bother using Javascript for it?</p>
<p>One reason may be to use query strings to pass information on pages that don&#8217;t have any server side scripting enabled.  I was looking into a web design competition for high school students, and it doesn&#8217;t allow any server-side scripts &#8211; only HTML, CSS, and Javascript.</p>
<p>With this method, we could use query strings to bring a little dynamism to the party.</p>
<p>This is also helpful for reading query strings in general &#8211; not just the one in the request string.  For example, if you use Ajax to get a value from a php script, how is the output formatted?</p>
<p>It may be plain text if it&#8217;s just one variable, or it may be in an XML format.  If the output is just a handful of key-value pairs, it might be easier and more efficient to create a query string and parse it with this function.</p>
<p>Or&#8230; maybe it&#8217;s just fun to say &#8220;I can do this.&#8221;  That&#8217;s a good enough reason for me.</p>
<p>And as usual, here&#8217;s the full function, in case you had some trouble.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> parseQueryString<span style="color: #009900;">&#40;</span>fullHref<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> hrefParts <span style="color: #339933;">=</span> fullHref.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//  [0] is the URL, [1] is the query string</span>
  <span style="color: #003366; font-weight: bold;">var</span> query <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span>hrefParts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> valuePairs <span style="color: #339933;">=</span> query.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> getArray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span> each <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> pair <span style="color: #000066; font-weight: bold;">in</span> valuePairs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// [0] = key, [1] = value</span>
    <span style="color: #003366; font-weight: bold;">var</span> tempPair <span style="color: #339933;">=</span> pair.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Unescape converts the text back from URL encoding</span>
    getArray<span style="color: #009900;">&#91;</span>tempPair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> unescape<span style="color: #009900;">&#40;</span>tempPair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> getArray<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//  To use it, pass the request string or another href</span>
<span style="color: #006600; font-style: italic;">//  to the function.  It returns the array.</span>
<span style="color: #003366; font-weight: bold;">var</span> href <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> getArray <span style="color: #339933;">=</span> parseQueryString<span style="color: #009900;">&#40;</span>href<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/03/04/use-javascript-to-parse-a-query-string/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Javascript Strings: How to Do String Replacement in JS</title>
		<link>http://www.earn-web-cash.com/2008/02/22/javascript-str-replace/</link>
		<comments>http://www.earn-web-cash.com/2008/02/22/javascript-str-replace/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 20:55:31 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[JS Tutorials]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/22/javascript-str-replace/</guid>
		<description><![CDATA[This morning I set about making a simple script to clean extra newline characters out of text. I could easily have processed the form contents in PHP, but I wanted to use Javascript to avoid reloading the page. The concept seemed simple enough, but I ran into a problem &#8211; I didn&#8217;t know how to [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I set about making a simple <a href="http://www.earn-web-cash.com/online-tools-design/text-cleaner-form/">script to clean extra newline characters</a> out of text.  I could easily have processed the form contents in PHP, but I wanted to use Javascript to avoid reloading the page.</p>
<p>The concept seemed simple enough, but I ran into a problem &#8211; I didn&#8217;t know how to do string replacement in Javascript.  The first thing I thought was, &#8220;What is the Javascript equivalent to str_replace?&#8221;<br />
<span id="more-152"></span></p>
<h5>The JS str_replace &#8211; String.replace()</h5>
<p>As it turns out, the closest thing in Javascript to str_replace is the replace method of the String class.  It&#8217;s actually more akin to preg_replace &#8211; since it uses regular expressions &#8211; but it&#8217;s the closest thing I could find for a built-in string replacement function.</p>
<p>It&#8217;s implementation is pretty simple.  Create a new string object.  Then call the replace method with two parameters &#8211; a regular expression to match and a string to replace it with.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> hello <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello World!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> goodbye <span style="color: #339933;">=</span> hello.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/hello/i</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Goodbye'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this example, we do a simple search for the word &#8216;hello&#8217; (the &#8216;i&#8217; signifies that the search is case insensitive).  When we find &#8216;hello,&#8217; we replace it with goodbye.</p>
<h5>Using Variable Values Inside Regex</h5>
<p>That&#8217;s simple enough.  However, what if you don&#8217;t want to hard-code the regular expression?</p>
<p>I was left wondering how I could use a variables value within the regular expression for the search.  If I placed the variable inside the / / boundaries of the regex, it would simply search for the name of the variable.</p>
<p>I eventually stumbled across the RegExp class &#8211; which incidentally makes it easier to build a regex expression.  You create an instance of the RegExp class by passing it two parameters &#8211; the string to match and any modifiers (&#8216;i&#8217; or &#8216;g&#8217;) that should be used for the search.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> hello <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello World!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> matchWord <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hello'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> match <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span>matchWord<span style="color: #339933;">,</span> <span style="color: #3366CC;">'i'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> goodbye <span style="color: #339933;">=</span> hello.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>match<span style="color: #339933;">,</span> <span style="color: #3366CC;">'Goodbye'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This has the same effect as the last example &#8211; except now the string to match comes from the variable matchWord.  With this, you could use some type of user input to determine what to match and replace.</p>
<h5>Recap &#8211; Replacing Strings in Javascript</h5>
<p>To recap&#8230;</p>
<ul>
<li>There is no direct equivalent to str_replace in Javascript.</li>
<li>Use String.replace &#8211; which is very similar to preg_replace.</li>
<li>Two parameters &#8211; a regex to match and a string to replace it with.</li>
<li>Build an instance of the RegExp class to use variable values in your regex.</li>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/22/javascript-str-replace/feed/</wfw:commentRss>
		<slash:comments>2</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 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>New Script: PHP Length Conversion Class</title>
		<link>http://www.earn-web-cash.com/2008/02/10/new-php-class-length/</link>
		<comments>http://www.earn-web-cash.com/2008/02/10/new-php-class-length/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 21:42:02 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/10/new-php-class-length/</guid>
		<description><![CDATA[I was looking for a project to tackle today, and I decided to make a script that would convert lengths from one unit or system to another.  

It doesn't sound all that complicated - and it's not.]]></description>
			<content:encoded><![CDATA[<p>I was looking for a project to tackle today, and I decided to make a script that would convert lengths from one unit or system to another.  </p>
<p>It doesn&#8217;t sound all that complicated &#8211; and it&#8217;s not.  I had a working script in a few minutes, but I didn&#8217;t like it.  It had too many functions to do conversions for individual units.  I wanted this script to be pretty well abstracted so that I could easily add new unit types &#8211; and so that the source code for the class would be very short.<br />
<span id="more-109"></span><br />
You can see what I came up with at the <a href="http://www.earn-web-cash.com/scripts-plugins-and-modules/length-class-convert-units/">PHP Length Conversion Class</a> page.</p>
<h5>The Concept Behind the Class</h5>
<p>Here&#8217;s the concept I came up with to help standardize the class, make the code manage-able, and make it adaptable.</p>
<p>First, when the length class is constructed the unit of length is converted to meters.  By having a standard format, it cuts down a lot on the number of conversions I need to worry about.  Although it means that each value will be converted twice (from the original into meters and then from meters into the next), it cuts down a lot on overhead.</p>
<p>Originally, I had written functions to convert from one type to meters and vice versa.  This was fine when I just had five data types, but I could see it would quickly get out of hand &#8211; and it would be tough to add new unit types.</p>
<p>I decided that I needed a data file (or a hard-coded data array in the class).  I came up with a format for an xml file that holds all the pertinent information &#8211; the abbreviation and the ratio of the unit type to meters.</p>
<p>Now, the class can read the XML file, create an array of available data types, and quickly convert between one unit type and another.  This enabled me to standardize the class methods &#8211; so now it only contains a handful of methods.</p>
<p>It could use some robustness in the way of data checking and error reporting &#8211; but for the moment I&#8217;m assuming the implementer checks that the data being passed to the class is the proper type.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/10/new-php-class-length/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Modify a WordPress RSS Feed Widget with Rel=Nofollow</title>
		<link>http://www.earn-web-cash.com/2008/02/09/modify-widget-nofollow/</link>
		<comments>http://www.earn-web-cash.com/2008/02/09/modify-widget-nofollow/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 00:34:11 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/09/modify-widget-nofollow/</guid>
		<description><![CDATA[I just added an RSS feed widget to my site (see the lower right corner &#8211; the DZone links). I frequent dZone a decent amount, and I find a lot of the articles interesting. However, after some thought I became concerned that ten sitewide external links might be a bit of a drain on my [...]]]></description>
			<content:encoded><![CDATA[<p>I just added an RSS feed widget to my site (see the lower right corner &#8211; the DZone links).  I frequent dZone a decent amount, and I find a lot of the articles interesting.</p>
<p>However, after some thought I became concerned that ten sitewide external links might be a bit of a drain on my pagerank.  If only I could add &#8220;rel=nofollow&#8221; to all those links.  But there&#8217;s no option in the RSS Widget to do that.<br />
<span id="more-106"></span><br />
Well, I decided to dive in and fix it myself.</p>
<h5>Where the RSS Feed Widget is Located</h5>
<p>This is actually a very simple hack to the WordPress source files.  You&#8217;ll need to edit two lines of the file, upload it, and you should be good to go.</p>
<p>The file we&#8217;re looking for is &#8220;widgets.php&#8221; &#8211; it should be located in the wp-includes folder.  This holds all the functions related to creating widgets and it also holds the standard widgets available in the Dashboard.</p>
<p>We need to scroll down, find the &#8220;RSS Feed Widget,&#8221; find where the links are created, and add &#8220;rel=&#8217;nofollow&#8217;&#8221; to those anchor tags.</p>
<h5>Hack It Up &#8211; Add Some Code</h5>
<p>The function we&#8217;re looking for should be around line 935 &#8211; titled &#8220;wp_widget_rss.&#8221;  Once you&#8217;ve found the function, look for this line &#8211; it should be around 965.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$url</span>' title='&quot;</span> <span style="color: #339933;">.</span> 
  attribute_escape<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Syndicate this content'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&gt;&lt;img 
  style='background:orange;color:white;border:none;' 
  width='14' height='14' src='<span style="color: #006699; font-weight: bold;">$icon</span>' alt='RSS' /&gt;&lt;/a&gt; 
  &lt;a class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$link</span>' title='<span style="color: #006699; font-weight: bold;">$desc</span>'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This creates the &#8220;RSS Icon&#8221; link to the original feed.  There&#8217;s a second link in there that makes the link for the title of the RSS feed.  To make these nofollow, simply add the phrase <code>rel='nofollow'</code> right after the <code>&lt;a</code>.  Be sure to use single quotes around the nofollow &#8211; or else you&#8217;ll break the PHP statement and cause an error.</p>
<p>When complete, it should look like this.  Notice that we&#8217;re adding rel=&#8217;nofollow&#8217; in two places.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a rel='nofollow' class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$url</span>' title='&quot;</span> <span style="color: #339933;">.</span> 
  attribute_escape<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Syndicate this content'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&gt;&lt;img 
  style='background:orange;color:white;border:none;' 
  width='14' height='14' src='<span style="color: #006699; font-weight: bold;">$icon</span>' alt='RSS' /&gt;&lt;/a&gt; 
  &lt;a rel='nofollow' class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$link</span>' title='<span style="color: #006699; font-weight: bold;">$desc</span>'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now scroll down a bit more to roughly line 990.  The line we&#8217;re looking for creates the individual links to the articles.  You should see this bit of code.</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;">&quot;&lt;li&gt;&lt;a class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$link</span>'
  title='<span style="color: #006699; font-weight: bold;">$desc</span>'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/a&gt;<span style="color: #006699; font-weight: bold;">$summary</span>&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Again, add <code>rel='nofollow'</code> right after the <code>&lt;a</code>.  The result should look 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: #0000ff;">&quot;&lt;li&gt;&lt;a rel='nofollow' class='rsswidget' href='<span style="color: #006699; font-weight: bold;">$link</span>'
  title='<span style="color: #006699; font-weight: bold;">$desc</span>'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/a&gt;<span style="color: #006699; font-weight: bold;">$summary</span>&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Upload the File</h5>
<p>That&#8217;s it.  Those two small changes should make your RSS Widgets nofollow from now on &#8211; preserving your pagerank.</p>
<p>Simply upload the file to the server (be sure to replace the old wp-includes/widgets.php) and reload your site.</p>
<p>If you run into an error, double check that you used single quotes around the &#8216;nofollow.&#8217;  The PHP string is started with a double quote (&#8220;), so if you place a double-quote there you&#8217;ll prematurely end the string &#8211; and cause a parse error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/09/modify-widget-nofollow/feed/</wfw:commentRss>
		<slash:comments>15</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>
		<item>
		<title>How to Create Multi-Page Forms in PHP, Revisited</title>
		<link>http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/</link>
		<comments>http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 00:59:26 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/</guid>
		<description><![CDATA[A couple weeks ago, I wrote a short article about how to create a multi-page form. The simple solution I suggested involved a foreach loop that cycled through the $_POST array and sent every value along in a hidden input element. After a bit of reflection (and some useful comments), I realized there&#8217;s a teeny [...]]]></description>
			<content:encoded><![CDATA[<p>A couple weeks ago, I wrote a short article about <a href="http://www.earn-web-cash.com/2008/01/27/multi-page-form/">how to create a multi-page form</a>.</p>
<p>The simple solution I suggested involved a foreach loop that cycled through the $_POST array and sent every value along in a hidden input element.  After a bit of reflection (and some useful comments), I realized there&#8217;s a teeny tiny security hole in that approach &#8211; so I&#8217;ve slightly modified it to close the loophole.<br />
<span id="more-103"></span></p>
<h5>The Multi-Page Form Snippet</h5>
<p>The old snippet of code looked like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</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;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> 
    <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h5>The Security Loophole</h5>
<p>What&#8217;s the problem?  If someone enters a quote into the form, it could break all of the hidden elements.  Here&#8217;s an example.</p>
<p>Let&#8217;s say I type this into a text input.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&quot; /&gt;&lt;input type=&quot;text&quot; name=&quot;newField&quot; value=&quot;newValue</pre></div></div>

<p>The next page would create this&#8230;</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;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstField&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;newField&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;newValue&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>By adding a quote, you prematurely end the first hidden element and can add new html tags.  You can combine this with javascript for some potentially nasty effects.  I guess.  I&#8217;m really not sure <strong>what</strong> you could do with this&#8230; but it&#8217;s better to be safe than sorry, eh?</p>
<h5>How to Fix the Multi-Page Form Snippet</h5>
<p>We can close this loophole once and for all with a simple function call &#8211; htmlentities.  With the proper parameter, this will encode all html entity characters (including quotes), so that the user can&#8217;t input a quote or create new HTML tags.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</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;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> 
    <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>No more problems.</p>
<p>It&#8217;s also important to note that this problem isn&#8217;t just a security loophole.  By not validating the input before creating the hidden element, you could accidentally break the form for a legitimate user.  If the user enters a &#8221; inside a text field, it would break the hidden element on the next page.</p>
<h5>Why Not Use Sessions or a Database?</h5>
<p>Some people have suggested using sessions or a database to accomplish the same thing.  That&#8217;s certainly possible, but I feel this is a better design choice.</p>
<p>I like to keep the php and html as separate as possible.  This allows us to keep all of the input inside of the form until we&#8217;re ready to process it.  Meanwhile, our processing script sees all of the input as coming from a single form &#8211; even if it came from different pages.</p>
<p>By contrast, you need to break up your processing script to use databases.  You also need to mix and match $_POST and $_SESSION to use sessions to store the information.  It&#8217;s functional, but doesn&#8217;t seem elegant to me.</p>
<p>With that in mind, this is something of a preference.  It&#8217;s not better than the other methods &#8211; but I think it is semantically more logical.  So use what you prefer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Submit Graphics Tutorials to GimpTutorials.com for Traffic</title>
		<link>http://www.earn-web-cash.com/2008/02/01/gimp-tutorials/</link>
		<comments>http://www.earn-web-cash.com/2008/02/01/gimp-tutorials/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 23:09:10 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Redirected]]></category>
		<category><![CDATA[Traffic]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/01/gimp-tutorials/</guid>
		<description><![CDATA[If you write tutorials on your website or blog, then niche tutorial directories are a great source of traffic.  I list most of my php tutorials with good-tutorials and get a nice <a href="http://www.earn-web-cash.com/2008/01/18/good-tutorialscom-niche-article-sites-to-help-increase-traffic/">burst of traffic</a> with each new listing.

Another site I've found useful is <a href="http://www.gimp-tutorials.com" title="Gimp Tutorial Site">Gimp Tutorials</a>.  They're a great place to list any graphics tutorials that you write for the GIMP graphic design program.]]></description>
			<content:encoded><![CDATA[<p>If you write tutorials on your website or blog, then niche tutorial directories are a great source of traffic.  I list most of my php tutorials with good-tutorials and get a nice <a href="http://www.earn-web-cash.com/2008/01/18/good-tutorialscom-niche-article-sites-to-help-increase-traffic/">burst of traffic</a> with each new listing.</p>
<p>Another site I&#8217;ve found useful is <a href="http://www.gimp-tutorials.com" title="Gimp Tutorial Site">Gimp Tutorials</a>.  They&#8217;re a great place to list any graphics tutorials that you write for the GIMP graphic design program.<br />
<span id="more-92"></span><br />
In case you don&#8217;t know what GIMP is, head to the <a href="http://www.gimp.org/" title="Gimp Homepage">Gimp</a> homepage.  It&#8217;s a free, open source graphic editing suite &#8211; similar in many ways to the expensive, proprietary Adobe Photoshop.</p>
<p><a href="http://www.gimp-tutorials.com" title="Gimp Tutorial Site">Gimp Tutorials</a> is another niche directory where you can submit appropriate tutorials for listing.  In this case, appropriate means just about anything related to creating or editing an image in Gimp.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/gimp-tutorials-analytics.png' title='Screenshot of Analytics Data for Referrals from Gimp Tutorials'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/02/gimp-tutorials-analytics.thumbnail.png' alt='Screenshot of Analytics Data for Referrals from Gimp Tutorials' /></a>I wrote a very basic tutorial to show users <a href="http://www.earn-web-cash.com/2008/01/24/how-to-create-a-gradient-background-image-in-gimp/" title="GIMP Gradient Image Tutorial">how to create a gradient background image in GIMP</a>.  Since I submitted the tutorial to Gimp Tutorials, slightly less than week ago, they&#8217;ve sent me 200 visits.</p>
<p>There was a brief spike on the first day, and I&#8217;ve been getting a steady stream of 20-30 visitors each day after that.</p>
<p>There doesn&#8217;t appear to be a lot of turnover on the site, so my tutorial is still listed third on the front page.  That&#8217;s after five days.  That&#8217;s a pretty lengthy period of exposure &#8211; considering that others sites (like Good Tutorials) turnover in about a day.</p>
<p>So if you write any tutorials for GIMP, don&#8217;t hesitate to submit them here.  It&#8217;s a good way to drive a few extra users to your latest article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/01/gimp-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

