<?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; PHP Development</title>
	<atom:link href="http://www.parorrey.com/blog/category/php-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parorrey.com/blog</link>
	<description>random bits on web development</description>
	<lastBuildDate>Tue, 07 Sep 2010 10:17:51 +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>
</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>
</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>How to show/hide divs based on radio button selection using jQuery</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-showhide-divs-based-on-radio-button-selection-using-jquery/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-showhide-divs-based-on-radio-button-selection-using-jquery/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 09:33:46 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=113</guid>
		<description><![CDATA[If you want a radio button selection to show certain Div contents and hide some other Div on the web page, and on another radio button selection, you need a different Div associated with that radio button hiding the unwanted one, read on. This can be achieved very efficiently using jQuery. We can put the [...]


No related posts.]]></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-showhide-divs-based-on-radio-button-selection-using-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-showhide-divs-based-on-radio-button-selection-using-jquery%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you want a radio button selection to show certain Div contents and hide some other Div on the web page, and on another radio button selection, you need a different Div associated with that radio button hiding the unwanted one, read on.</p>
<p>This can be achieved very efficiently using jQuery. We can put the code inside &#8220;click&#8221; or &#8220;change&#8221; event of radio button group,</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name$='group_name']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and after getting the value of selected radio button by this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> radio_value <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can simply hide or show our required Divs using following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>radio_value<span style="color: #339933;">==</span><span style="color: #3366CC;">'Yes'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#no_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here’s putting every together, simply put this code in your page inside script tags and it will work.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name$='group_name']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> radio_value <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><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;">if</span><span style="color: #009900;">&#40;</span>radio_value<span style="color: #339933;">==</span><span style="color: #3366CC;">'Yes'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#no_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</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;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>radio_value<span style="color: #339933;">==</span><span style="color: #3366CC;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#no_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#no_box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<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-showhide-divs-based-on-radio-button-selection-using-jquery%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-showhide-divs-based-on-radio-button-selection-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to unzip files on remote server using PHP script</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-unzip-files-on-remote-server-using-php-script/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-unzip-files-on-remote-server-using-php-script/#comments</comments>
		<pubDate>Mon, 24 May 2010 10:32:19 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[uncompress]]></category>
		<category><![CDATA[unzipping]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=106</guid>
		<description><![CDATA[Uploading files to server is a daily chore every webmaster has to do and if you do it using some ftp client where each and every file and image, no matter how small it might be, is uploaded separately, it’s a real pain. Sometimes, It takes hours to get these files uploaded and even then [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/' rel='bookmark' title='Permanent Link: Copying files from remote server to another server through SSH'>Copying files from remote server to another server through SSH</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-unzip-files-on-remote-server-using-php-script%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-unzip-files-on-remote-server-using-php-script%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Uploading files to server is a daily chore every webmaster has to do and if you do it using some ftp client where each and every file and image, no matter how small it might be, is uploaded separately, it’s a real pain. Sometimes, It takes hours to get these files uploaded and even then some files are skipped somehow.</p>
<p>A very easy solution to this tedious task is to upload a compressed zip or tar file and uncompress it on server. If you have SSH access or your hosting control panel provide you extracting your compressed file, it’s very helpful. For instance, CPanel and HSphere provide both zipping and unzipping of files and folders on server. But not all hosting environments allow you to unzip files on server without SSH access.</p>
<p>An easy way to unzip file on server is to use following php script.</p>
<p>Just provide the zip file name and destination folder to extract files in the script and it will extract your files for you saving you hours of uploading headache.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$destination</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/destination'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//blank for root folder</span>
&nbsp;
  <span style="color: #000088;">$zip</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ZipArchive<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$zip_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$zip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.zip'</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: #000088;">$zip_file</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000088;">$zip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extractTo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$destination</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$zip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'files successfully extracted to
      &lt;strong&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$destination</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'
     &lt;/strong&gt; directory.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No donuts for you. :('</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hope it 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-unzip-files-on-remote-server-using-php-script%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/' rel='bookmark' title='Permanent Link: Copying files from remote server to another server through SSH'>Copying files from remote server to another server through SSH</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-unzip-files-on-remote-server-using-php-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/MySQL datetime formatting bypassing UNIX_TIMESTAMP</title>
		<link>http://www.parorrey.com/blog/php-development/phpmysql-datetime-formatting-bypassing-unix-timestamp/</link>
		<comments>http://www.parorrey.com/blog/php-development/phpmysql-datetime-formatting-bypassing-unix-timestamp/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 14:41:30 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[format date]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=100</guid>
		<description><![CDATA[PHP/MySQL datetime formatting bypassing UNIX_TIMESTAMP Formatting MySQL date to something useful has been a pain for PHP developers for a long time. Usually you would make your query return the datetime using UNIX_TTIMESTAMP and then using PHP date function, format it to your heart&#8217;s content like this: echo date&#40;&#34;F jS, Y h:i:s A&#34;, $row-&#62;date&#41;; But [...]


No related posts.]]></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%2Fphpmysql-datetime-formatting-bypassing-unix-timestamp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fphpmysql-datetime-formatting-bypassing-unix-timestamp%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<h2>PHP/MySQL datetime formatting bypassing UNIX_TIMESTAMP</h2>
<p>Formatting <strong>MySQL</strong> date to something useful has been a pain for PHP developers for a long time. </p>
<p>Usually you would make your query return the datetime using <strong>UNIX_TTIMESTAMP</strong> and then using PHP date function, format it to your heart&#8217;s content 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: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F jS, Y h:i:s A&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this method has a downside, you can’t use the * and have to put all the fields in the query to use UNIX_TIMESTAMP for datetime field and have it returned as timestamp.  </p>
<p>A better way of doing this is, especially in the scenario when you have to use * in the query, by using <strong>PHP5 DateTime Object</strong>. This way you can avoid UNIX_TIMESTAMP.  </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myDate</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$oDate</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F jS, Y h:i:s A &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Hope it 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%2Fphpmysql-datetime-formatting-bypassing-unix-timestamp%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/phpmysql-datetime-formatting-bypassing-unix-timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FBJS Quick Jump Menu for a FBML Facebook Platform App</title>
		<link>http://www.parorrey.com/blog/php-development/fbjs-quick-jump-menu-for-a-fbml-facebook-platform-app/</link>
		<comments>http://www.parorrey.com/blog/php-development/fbjs-quick-jump-menu-for-a-fbml-facebook-platform-app/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 14:30:20 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[Facebook Apps Development]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Facebook Apps]]></category>
		<category><![CDATA[FBJS]]></category>
		<category><![CDATA[FBML]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=81</guid>
		<description><![CDATA[In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS properly. Just change your standard js jump menu from: &#60;select onchange=&#34;goto(this.options[this.selectedIndex].value)&#34;&#62; &#60;option value=&#34;page.php?id=1&#34;&#62;Page1&#60;/option&#62; &#60;option value=&#34;page.php?id=2&#34;&#62;Page2&#60;/option&#62; &#60;option value=&#34;page.php?id=3&#34;&#62;Page3&#60;/option&#62; &#60;/select&#62; To this: &#60;select onchange=&#34;document.setLocation(this.getValue());&#34;&#62; &#60;option value=&#34;page.php?id=1&#34;&#62;Page1&#60;/option&#62; &#60;option value=&#34;page.php?id=2&#34;&#62;Page2&#60;/option&#62; &#60;option value=&#34;page.php?id=3&#34;&#62;Page3&#60;/option&#62; &#60;/select&#62; Cheers. Related posts:Facebook requires every developer to verify [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-requires-every-developer-to-verify-his-facebook-account-to-create-new-applications/' rel='bookmark' title='Permanent Link: Facebook requires every developer to verify his Facebook account to create new applications'>Facebook requires every developer to verify his Facebook account to create new applications</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-applications-will-automatically-upgrade-to-new-data-permissions-on-june-30/' rel='bookmark' title='Permanent Link: Facebook applications will automatically upgrade to new data permissions on June 30'>Facebook applications will automatically upgrade to new data permissions on June 30</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/graph-api-authorization-oauth-2-0-replacing-require-login/' rel='bookmark' title='Permanent Link: Facebook Graph API authentication OAuth 2.0 replacing Require Login'>Facebook Graph API authentication OAuth 2.0 replacing Require Login</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%2Ffbjs-quick-jump-menu-for-a-fbml-facebook-platform-app%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Ffbjs-quick-jump-menu-for-a-fbml-facebook-platform-app%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>In a <strong>FBML Facebook App</strong>, your quick jump menu will require a little tweak to work in <strong>FBJS</strong> properly.<br />
Just change your standard js jump menu from:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>select onchange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;goto(this.options[this.selectedIndex].value)&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=1&quot;</span><span style="color: #339933;">&gt;</span>Page1<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=2&quot;</span><span style="color: #339933;">&gt;</span>Page2<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=3&quot;</span><span style="color: #339933;">&gt;</span>Page3<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span></pre></div></div>

<p>To this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>select onchange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.setLocation(this.getValue());&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=1&quot;</span><span style="color: #339933;">&gt;</span>Page1<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=2&quot;</span><span style="color: #339933;">&gt;</span>Page2<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page.php?id=3&quot;</span><span style="color: #339933;">&gt;</span>Page3<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span></pre></div></div>

<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%2Ffbjs-quick-jump-menu-for-a-fbml-facebook-platform-app%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-requires-every-developer-to-verify-his-facebook-account-to-create-new-applications/' rel='bookmark' title='Permanent Link: Facebook requires every developer to verify his Facebook account to create new applications'>Facebook requires every developer to verify his Facebook account to create new applications</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-applications-will-automatically-upgrade-to-new-data-permissions-on-june-30/' rel='bookmark' title='Permanent Link: Facebook applications will automatically upgrade to new data permissions on June 30'>Facebook applications will automatically upgrade to new data permissions on June 30</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/graph-api-authorization-oauth-2-0-replacing-require-login/' rel='bookmark' title='Permanent Link: Facebook Graph API authentication OAuth 2.0 replacing Require Login'>Facebook Graph API authentication OAuth 2.0 replacing Require Login</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/fbjs-quick-jump-menu-for-a-fbml-facebook-platform-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to remove &#8220;setting session.bug_compat_42 or session.bug_compat_warn&#8221; Warning</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 14:23:03 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[php coding]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=77</guid>
		<description><![CDATA[I was adding some features in one of my older website for a client and saw this warning: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You [...]


No related posts.]]></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-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I was adding some features in one of my older website for a client and saw this warning:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Warning<span style="color: #339933;">:</span> Unknown<span style="color: #339933;">:</span> Your script  possibly relies on a 
session side<span style="color: #339933;">-</span>effect which existed until PHP 4<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>3<span style="color: #339933;">.</span>
Please  be advised that the session extension
 does not consider <span style="color: #000000; font-weight: bold;">global</span> variables <span style="color: #b1b100;">as</span> a 
source of data<span style="color: #339933;">,</span> unless register_globals is enabled<span style="color: #339933;">.</span>
You can disable this  functionality and 
this warning by setting session<span style="color: #339933;">.</span>bug_compat_42
 or  session<span style="color: #339933;">.</span>bug_compat_warn to off<span style="color: #339933;">,</span> respectively<span style="color: #339933;">.</span> 
in Unknown on line <span style="color:#800080;">0.</span></pre></div></div>

<p>You can simply resolve this and make this warning disappear by <strong>avoiding using the same names for session variables and normal ones.</strong></p>
<p>In my case, I just had to change the following code to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$type</span><span style="color: #339933;">;</span></pre></div></div>

<p>To this one:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$type</span><span style="color: #339933;">;</span></pre></div></div>

<p>That’s it!</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-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-remove-setting-session-bug_compat_42-or-session-bug_compat_warn-warning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix broken Facebook sample application &#8216;footprints&#8217;</title>
		<link>http://www.parorrey.com/blog/php-development/how-to-fix-broken-facebook-sample-application-footprints/</link>
		<comments>http://www.parorrey.com/blog/php-development/how-to-fix-broken-facebook-sample-application-footprints/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:50:24 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Facebook Applications]]></category>
		<category><![CDATA[footprints]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=64</guid>
		<description><![CDATA[So out of curiosity or some Facebook application development prospect forced you today to check on a Facebook application and which brought you here to this blog post. After signing up for Facebook Apps and downloading facebook-platform.tar.gz, you find a sample application named ‘footprints’ inside it. Footprints App is kinda ‘Hello World’ of Facebook applications. [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/facebook-apps-development/graph-api-authorization-oauth-2-0-replacing-require-login/' rel='bookmark' title='Permanent Link: Facebook Graph API authentication OAuth 2.0 replacing Require Login'>Facebook Graph API authentication OAuth 2.0 replacing Require Login</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-requires-every-developer-to-verify-his-facebook-account-to-create-new-applications/' rel='bookmark' title='Permanent Link: Facebook requires every developer to verify his Facebook account to create new applications'>Facebook requires every developer to verify his Facebook account to create new applications</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-fix-broken-facebook-sample-application-footprints%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fhow-to-fix-broken-facebook-sample-application-footprints%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>So out of curiosity or some <strong>Facebook </strong>application development prospect  forced you today to check on a Facebook application and which brought you here to  this blog post.</p>
<p>After signing up for Facebook Apps and  downloading facebook-platform.tar.gz, you find a sample application named ‘<strong>footprints’</strong> inside it. <strong>Footprints App</strong> is kinda ‘Hello World’  of Facebook applications. </p>
<p> You uncompress the facebook-platform.tar.gz  file and follow instructions available in the README file.You are required to do a number of steps before  seeing your FB App ‘Hello World’:</p>
<ul>
<li>Setup the DB information in the  config.php file, </li>
<li>Create the required table in your DB as described by config.php </li>
<li>get the app registered on  Develop Page, </li>
<li>Setup application name, get API  Key and Secret key </li>
<li>Add these keys in the  config.php file </li>
<li>Upload the whole directory on your  online server, </li>
<li>Open your FB Developer’s page,  select your demo application,  and click &#8216;Edit  Settings&#8217;, add <strong>Canvas Page URL</strong> on Facebook for your application, and add <strong>Canvas Callback URL</strong> (where you  uploaded your application) on <strong>Canvas  page</strong>. </li>
</ul>
<p>Now  to view your application, you open this http://apps.facebook.com/your-footprints/  where <strong>your-footprints</strong> is what you defined in the Canvas Page URL.</p>
<p>Pretty cool, isn’t it? Yeah right as long  as you don’t type in your friend’s name and click ‘step’.</p>
<p>This is the warning message on line 52 and  a fatal error on line 58 as soon as you hit ‘step’</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">&quot;Warning: Missing  argument 3 for FacebookRestClient::notifications_send()&quot;</span>
<span style="color: #0000ff;">&quot;Fatal error: Call to  undefined method FacebookRestClient::feed_publishActionOfUser&quot;</span></pre></div></div>

<p>To remove this warning and fatal  error, follow these steps:</p>
<p>Just add a third argument (any string would do) in function <strong>notifications_send()</strong> call. Just add this on line 52 in <strong>lib.php</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #0000ff;">'&lt;a href=&quot;http://apps.facebook.com/fc-footprints/&quot;&gt;See all your Footprints&lt;/a&gt;.'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'your_app_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the same lib.php file, on line 58, replace function <strong>feed_publishActionOfUser</strong> with <strong>feed_publishUserAction </strong>which is defined in facebookapi_php5_restlib.php </pre>
</p>
<p>And by the way, don't forget  to change this URL <strong>http://apps.facebook.com/footprints/</strong> in lib.php on several places to your own application's url e.g. http://apps.facebook.com/your-footprints/ </p>
<p>I 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-fix-broken-facebook-sample-application-footprints%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/facebook-apps-development/graph-api-authorization-oauth-2-0-replacing-require-login/' rel='bookmark' title='Permanent Link: Facebook Graph API authentication OAuth 2.0 replacing Require Login'>Facebook Graph API authentication OAuth 2.0 replacing Require Login</a></li>
<li><a href='http://www.parorrey.com/blog/facebook-apps-development/facebook-requires-every-developer-to-verify-his-facebook-account-to-create-new-applications/' rel='bookmark' title='Permanent Link: Facebook requires every developer to verify his Facebook account to create new applications'>Facebook requires every developer to verify his Facebook account to create new applications</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/php-development/how-to-fix-broken-facebook-sample-application-footprints/feed/</wfw:commentRss>
		<slash:comments>1</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/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/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>
		<item>
		<title>Setting different cache age for different feeds using Magpie RSS &#8211; PHP RSS Parser</title>
		<link>http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/</link>
		<comments>http://www.parorrey.com/blog/php-development/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 10:45:27 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[MagpieRSS]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[RSS feeds]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=15</guid>
		<description><![CDATA[MagpieRSS is a XML-based RSS parser in PHP. MagpieRSS supports most RSS versions including modules and namespaces. Magpie RSS also supports caching which is kind a must while parsing any feed because you don’t want to fetch the feed for every hit on your website and risk getting banned. Although Magpie RSS is really useful [...]


Related posts:<ol><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>
<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%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fphp-development%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong><a href="http://magpierss.sourceforge.net/" target="_blank">MagpieRSS</a></strong> is a XML-based RSS parser in PHP. <strong>MagpieRSS</strong> supports most RSS versions including modules and namespaces. Magpie RSS also supports caching which is kind a must while parsing any feed because you don’t want to fetch the feed for every hit on your website and risk getting banned.</p>
<p>Although <strong>Magpie RSS</strong> is really useful and I&#8217;ve used it in many projects, one of the feature which is missing from Magpie is setting different cache ages. I had to setup few feeds in a website recently and set different caching age for different feeds. If you are facing similar problem, read on to check the solution. </p>
<p>I made few following changes in the code of function <strong>function fetch_rss</strong>  inside  &#8216;rss_fetch.php&#8217; file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;">/*added 2nd parameter for setting different cache age and set existing MAGPIE_CACHE_AGE as default */</span>
<span style="color: #000000; font-weight: bold;">function</span> fetch_rss <span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$magpie_cache_age</span><span style="color: #339933;">=</span>MAGPIE_CACHE_AGE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// initialize constants</span>
    init<span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fetch_rss called without a url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if cache is disabled</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>MAGPIE_CACHE_ON <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// fetch file, and parse it</span>
        <span style="color: #000088;">$resp</span> <span style="color: #339933;">=</span> _fetch_remote_file<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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_success<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$resp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> _response_to_rss<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$resp</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to fetch <span style="color: #006699; font-weight: bold;">$url</span> and cache is off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #666666; font-style: italic;">// else cache is ON</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Flow</span>
        <span style="color: #666666; font-style: italic;">// 1. check cache</span>
        <span style="color: #666666; font-style: italic;">// 2. if there is a hit, make sure its fresh</span>
        <span style="color: #666666; font-style: italic;">// 3. if cached obj fails freshness check, fetch remote</span>
        <span style="color: #666666; font-style: italic;">// 4. if remote fails, return stale object, or error</span>
&nbsp;
       <span style="color: #666666; font-style: italic;">//we are not using constant MAGPIE_CACHE_AGE rather using parameter age **added by parorrey**</span>
	   <span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RSSCache<span style="color: #009900;">&#40;</span> MAGPIE_CACHE_DIR<span style="color: #339933;">,</span> <span style="color: #000088;">$magpie_cache_age</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that was it. Now you can call the function <strong>fetch_rss</strong> with the cache age different than the default MagpisRSS cache age defined in constant <strong>MAGPIE_CACHE_AGE</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&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: #339933;">,</span> <span style="color: #cc66cc;">3600</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">12</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//3600 * 12 means 12 hours</span></pre></div></div>

<p>You can call the function with one (default) parameter and it&#8217;ll still work just fine albeit caching the feed to default cache age.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&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>  <span style="color: #666666; font-style: italic;">//default cache age</span></pre></div></div>

<p>Hopefully it&#8217;ll help someone setting different <strong>cache ages</strong> for different RSS feeds in <strong>MagpieRSS</strong>.</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%2Fsetting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><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>
<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/setting-different-cache-age-for-different-feeds-using-magpie-rss-php-rss-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
