<?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>myXMLProject &#187; PHP</title>
	<atom:link href="http://www.myxmlproject.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myxmlproject.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 05 Jun 2011 23:58:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Customize RSS Feeds with PHP</title>
		<link>http://www.myxmlproject.com/customize-rss-feeds-with-php/</link>
		<comments>http://www.myxmlproject.com/customize-rss-feeds-with-php/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 23:15:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.myxmlproject.com/?p=24</guid>
		<description><![CDATA[Customize the display of your RSS feed using HTML and PHP.  Starting with PHP version 5, SimpleXML loads, and parses an XML document. SimpleXML makes it easier to get access to xml content.  Take a look at this simple example.  

PHP provides a nice solution for inserting RSS feeds into an HTML [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Customize the display of your RSS feed using HTML and PHP.  Starting with PHP version 5, SimpleXML loads, and parses an XML document. SimpleXML makes it easier to get access to xml content.  Take a look at this simple example.</strong>  </p>
<p><span id="more-24"></span><br />
PHP provides a nice solution for inserting RSS feeds into an HTML document.  Unlike previous XML implementations, SimpleXML uses the XML tag names as variables.  <a href="http://cyber.law.harvard.edu/rss/rss.html" target="blank" class="uline">If you need a refresher on the RSS 2.0 specification take a look at this site.</a></p>
<p>Here is the PHP code:</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;?php</span></span>
<span style="color: #009900;">if <span style="color: #66cc66;">&#40;</span>isset<span style="color: #66cc66;">&#40;</span>$_GET<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'category'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #009900;">  $rssfeed_category = <span style="color: #66cc66;">&#40;</span>get_magic_quotes_gpc<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> ? $_GET<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'category'</span><span style="color: #66cc66;">&#93;</span> : addslashes<span style="color: #66cc66;">&#40;</span>$_GET<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'category'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">else</span>
<span style="color: #009900;">  $rssfeed_category = <span style="color: #ff0000;">'http://rss.news.yahoo.com/rss/topstories'</span>;</span>
<span style="color: #009900;">  libxml_use_internal_errors<span style="color: #66cc66;">&#40;</span>true<span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #009900;">  if <span style="color: #66cc66;">&#40;</span>$rssfeed = simplexml_load_file<span style="color: #66cc66;">&#40;</span>$rssfeed_category<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">     foreach <span style="color: #66cc66;">&#40;</span>$rssfeed-<span style="color: #000000; font-weight: bold;">&gt;</span></span>channel as $channel) {
        echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h2<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;' . $channel-&gt;</span></span>link . '&quot;&gt;' .
				$channel-&gt;title . '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/h2<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
        echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>' . $channel-&gt;description . '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
&nbsp;
        foreach ($channel-&gt;item as $item) {
           echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;rssItem&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>';
           echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
           echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;' . $item-&gt;</span></span>link . '&quot; class=&quot;rssLink&quot;&gt;';
           echo $item-&gt;title . '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>';
           echo $item-&gt;description . '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
           echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
           echo '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
        }
   }
}
else echo 'RSS feed could not be read. ' . $rssfeed_category . '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>';
?&gt;</pre></div></div>

<p>Tips to making this work:</p>
<ul>
<li>Reserved HTML characters such as ampersand (&amp;) and greater than(&gt;) can cause problems if they appear as ordinary text in an XML document. The browser will mistake these reserved characters for markup.  Use the php function <strong>htmlentities</strong> to convert characters such as &amp; to &amp;amp; if this becomes a problem.</li>
<li>Many RSS feeds contain HTML markup for formatting purposes.  In this case, htmlentities is NOT recommened.  <a href="http://www.myxmlproject.com/projects/parserss/rsstest.php?category=http://www.news.ucdavis.edu/xml/getnews.php/rss/category/Environmental%20Sciences"  target="blank" class="uline">Here&#8217;s an example of using htmlentities with description text containing HTML markup.</a>
<li>Character encoding can also lead to display problems.  To ensure proper display of special characters, pay attention to the character encoding.  UTF-8 is the default character encoding for XML.  ISO-8859-1 is more commonly used in HMTL.  If you use UTF-8 encoding in the HTML document&#8217;s head section, the special characters should print correctly.

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;</pre></div></div>

</li>
<li>A file access warning from simplexml_load_file() may indicate a server warning.  Check the php.ini configuration option <strong>allow_url_fopen = On</strong>.  This will give the simplexml_load_file() function the ability to open the remote rss file.  However it will not be good for website security because it leads to PHP Remote File Include Hacks.</li>
<p> RELATED POSTS:</p>
<ul>
<li><a href="http://www.w3schools.com/PHP/func_string_htmlentities.asp" target="blank" >PHP htmlentities</a></li>
<li><a href="http://cyber.law.harvard.edu/rss/rss.html" target="blank" >RSS 2.0 Specification</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.myxmlproject.com/customize-rss-feeds-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

