<?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>Ali Qureshi&#039;s Blog &#187; RSS Parser</title>
	<atom:link href="http://www.parorrey.com/blog/tag/rss-parser/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parorrey.com/blog</link>
	<description>random bits on web development</description>
	<lastBuildDate>Thu, 09 Sep 2010 10:45:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://www.parorrey.com/blog/?pushpress=hub'/>
		<item>
		<title>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:06:45 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[mediaRSS]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[RSS Parser]]></category>
		<category><![CDATA[SimplePie]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=145</guid>
		<description><![CDATA[If you ever faced a scenario where you had to parse the rss feed with image thumbnails placed inside &#8220;enclosure&#8221; tags, SimplePie is the perfect solution. In fact SimplePie can parse mediaRSS. There are several other php classes such as Magpie which can do the job as well. Magpie can parse rss2.0 enclosure but not [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/' rel='bookmark' title='Permanent Link: Parsing News Feed using PHP &#038; MagpieRSS and making it scroll'>Parsing News Feed using PHP &#038; MagpieRSS and making it scroll</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you ever faced a scenario where you had to parse the rss feed with image thumbnails placed inside &#8220;enclosure&#8221; tags, <a href="http://simplepie.org/" target="_blank"><strong>SimplePie</strong></a> is the perfect solution. In fact SimplePie can parse mediaRSS. There are several other php classes such as Magpie which can do the job as well. Magpie can parse rss2.0 enclosure but not mediaRSS and I had hard time getting enclosure parsed with Magpie. After spending hours, I tried Simple Pie and it worked like a charm.  </p>
<p>SimplePie is a fast and feature rich PHP class that is very simple to use.  </p>
<p>In few steps, you can use SimplePie to retrieve and parse any RSS or Atom feeds and display them on any PHP website. SimplePie also allows you to incorporate any type of data from any number of feeds. Here&#8217;s how you can setup SimplePie in three steps:</p>
<ul>
<li> <a href="http://simplepie.org/downloads/" target="_blank">Download SimplePie</a> and uncompress it    </li>
<li> Place the &#8220;simplepie.inc&#8221; into a your &#8220;includes&#8221; folder under root directory of your website and include it into your calling script    </li>
<li> Create a directory named &#8220;cache&#8221; (also in the web-accessible root directory) and make sure that it&#8217;s writable by the server (i.e., CHMOD to 755, 775, or 777)</li>
</ul>
<p>Here&#8217;s the sample code to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SIMPLEPIE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/path/to/simplepie.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>SIMPLEPIE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//include the simplepie class</span>
  <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.parorrey.com/blog/feed/'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// bake a new pie</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// provide feed url</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cache_duration</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// specify cache duration in seconds</span>
  <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// text/html utf-8 character encoding</span>
  <span style="color: #000088;">$check</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// script initialization check</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$check</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <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;">get_items</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$enclosure</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_enclosure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
   <span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$enclosure</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_link</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; 
       alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</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: #b1b100;">else</span> <span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$rss_feed</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;div class=&quot;rssItem&quot;&gt;
  &lt;span class=&quot;date&quot;&gt;
 '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j F Y @ g:i a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;
  &lt;h3&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;">get_permalink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; 
       title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;
      target=&quot;_blank&quot; rel=&quot;no-follow&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'
       &lt;br/&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$thumb</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/h3&gt;		
&lt;p&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_description</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;spacer dash&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>      
&nbsp;
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div id=&quot;rssNews&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$rss_feed</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>SimplePie also allows you to merge different rss feeds into one single stream.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'http://your-domain1.com/your-feed1/'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'http://your-domain2.com/your-feed2/'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'http://your-domain3.com/your-feed3/'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here is where the cache directory should exist if you are using the default cache location: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>your<span style="color: #339933;">/</span>feed_page<span style="color: #339933;">.</span>php
<span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>your<span style="color: #339933;">/</span>cache<span style="color: #339933;">/</span>
<span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>simplepie<span style="color: #339933;">/</span>way<span style="color: #339933;">/</span>deep<span style="color: #339933;">/</span>in<span style="color: #339933;">/</span>directory<span style="color: #339933;">/</span>simplepie<span style="color: #339933;">.</span>inc</pre></div></div>

<p>Please note that using ./cache (dot-slash-cache) means that the cache directory will be relative to the page that&#8217;s calling SimplePie, not SimplePie itself.
</p>
<p>Hope that helps.</p>
<p> Cheers! </p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/' rel='bookmark' title='Permanent Link: Parsing News Feed using PHP &#038; MagpieRSS and making it scroll'>Parsing News Feed using PHP &#038; MagpieRSS and making it scroll</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing News Feed using PHP &amp; MagpieRSS and making it scroll</title>
		<link>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/</link>
		<comments>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 13:48:13 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[MagpieRSS]]></category>
		<category><![CDATA[News Scroller]]></category>
		<category><![CDATA[News Ticker]]></category>
		<category><![CDATA[RSS feeds]]></category>
		<category><![CDATA[RSS Parser]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=46</guid>
		<description><![CDATA[A while back I had to develop a news widget/ticker as part of my PHP website development project. First part was to fetch news items regularly via RSS feed, cache the feed and parse it for displaying and for this I used MagpieRSS. Second part was to show the parsed news items as scrolling text [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/' rel='bookmark' title='Permanent Link: How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie'>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>A while back I had to develop a news widget/ticker as part of my <a href="http://www.parorrey.com/" target="_blank">PHP website development</a> project.</p>
<p>First part was to fetch news items regularly via RSS feed, cache the feed and parse it for displaying and for this I used <a rel="nofollow" href="http://magpierss.sourceforge.net/" target="_blank">MagpieRSS</a>. Second part was to show the parsed news items as scrolling text or news ticker on a web page.</p>
<p>But first things first, check the demo of what we are talking about <a rel="nofollow" href="http://www.parorrey.com/test/news-ticker/" target="_blank">Demo MagpieRSS News Scroller</a>. </p>
<p>Here is the PHP code for fetching and parsing the news items using MagpieRSS.</p>
<p>First of all, include the Magpie class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>MAGPIE_DIR<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss_fetch.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//where MAGPIE_DIR is the path to magpie dir</span></pre></div></div>

<p>Provide the url and set number of items to be displayed (Ideally these should come from Database as I did in the said project managed via admin panel of CMS.):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/business/rss.xml'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//set  $num_of_items = 'All' to show all items;</span></pre></div></div>

<p>Now parse the feed and store all the data in the <strong>$rss_news_items</strong> variable to be displayed in the page later.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> fetch_rss<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$rss_feed_name</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">'Channel: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Updated: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastbuilddate'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num_of_items</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'All'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_of_items</span><span style="color: #009900;">&#41;</span>  <span style="color: #000088;">$num_of_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rss_news_items</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_of_items</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$href</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$rss_news_items</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&amp;nbsp;&amp;nbsp;&lt;span class=&quot;bgwithtext&quot;&gt;&lt;b&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/b&gt; - '</span><span style="color: #339933;">.</span><span style="color: #000088;">$date</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;&lt;span class=&quot;linkTextOnly&quot;&gt;&amp;nbsp;&lt;b&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; target=&quot;_blank&quot; rel=&quot;no-follow&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$description</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&amp;nbsp;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now having parsed the RSS feed, we need to make news items scroll on page and for this I used this <a rel="nofollow" href="http://www.mioplanet.com/rsc/newsticker_javascript.htm" target="_blank">Scrolling News Ticker by Mioplanet</a>. </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;">$rss_feed_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;
&lt;div id=&quot;TICKER&quot; STYLE=&quot;overflow:hidden; width:520px&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$rss_news_items</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;webticker_lib.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Don&#8217;t forget to place &#8220;webticker_lib.js&#8221; from <a rel="nofollow" href="http://www.mioplanet.com/rsc/newsticker_javascript.htm" target="_blank">Mioplanet</a> website in the same directory as your php page. You may also want to place following css class in your style sheet.</p>
<p>I selected Mioplanet js scroller due to its usefulness. You can set the ticker directon from left to right or otherwise, ticker speed and its styles easily.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.bgwithtext</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> orange<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I have put together a working php script with all the dependent files in this zipped folder <a rel="nofollow" href="http://www.parorrey.com/downloads/news-ticker.zip">Download PHP MagpieRSS News Scroller script</a>. Just make sure you have &#8216;/cache&#8217; directory at the root of your website and it is writable by php script (with chmod permissions 777).</p>
<p>Hope that helps!</p>
<p>Cheers.</p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fparsing-news-feed-using-php-magpierss-and-making-it-scroll%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/' rel='bookmark' title='Permanent Link: Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser'>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</a></li>
<li><a href='http://www.parorrey.com/blog/php-development/how-to-fetch-parse-and-parse-cache-display-rss-atom-and-mediarss-feeds-using-simplepie/' rel='bookmark' title='Permanent Link: How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie'>How to fetch, parse, cache, and display your external RSS and Atom feeds and mediaRSS on your website using SimplePie</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/parsing-news-feed-using-php-magpierss-and-making-it-scroll/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
