<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: PHP Get File Extension</title>
	<atom:link href="http://cowburn.info/2008/01/13/get-file-extension-comparison/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/</link>
	<description>Online storage depot for Peter Cowburn</description>
	<lastBuildDate>Sat, 04 Feb 2012 12:58:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Peter</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71484</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 04 Feb 2012 12:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71484</guid>
		<description>Jacob, this is because &lt;code&gt;pathinfo()&lt;/code&gt; works on filesystem paths not URLs.  For your example with a URL, you could get the path by using &lt;a href=&quot;http://php.net/parse_url&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;parse_url()&lt;/code&gt;&lt;/a&gt;.

&lt;pre lang=&quot;php&quot;&gt;
$path = parse_url($url, PHP_URL_PATH);
$ext  = pathinfo($path, PATHINFO_EXTENSION);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Jacob, this is because <code>pathinfo()</code> works on filesystem paths not URLs.  For your example with a URL, you could get the path by using <a href="http://php.net/parse_url" rel="nofollow"><code>parse_url()</code></a>.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$ext</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jakob Sternberg</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71446</link>
		<dc:creator>Jakob Sternberg</dc:creator>
		<pubDate>Sat, 04 Feb 2012 02:57:52 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71446</guid>
		<description>The only thing that fails is if the path has a query line attached. Like 

&lt;pre lang=&quot;php&quot;&gt;echo pathinfo(&quot;http://mysite.com/page.php?file=msg.txt&quot;, PATHINFO_EXTENSION)&lt;/pre&gt;
- it will output &#039;txt&#039;

Just a note. easy to fix offcourse:

&lt;pre lang=&quot;php&quot;&gt;function getFileExtension($p) {
   if( strpos($p,&quot;?&quot;) != &#039;&#039; ) $p = substr($p, 0, strpos($p,&quot;?&quot;) ); 
   return pathinfo($p, PATHINFO_EXTENSION);
   }

echo getFileExtension(&quot;http://mysite.com/page.php?file=msg.txt&quot;)
&lt;/pre&gt;

- will output &#039;php&#039;

Thanks for the heads up on PATHINFO_EXTENSION!</description>
		<content:encoded><![CDATA[<p>The only thing that fails is if the path has a query line attached. Like</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mysite.com/page.php?file=msg.txt&quot;</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span></div></div>
<p>- it will output &#8216;txt&#8217;</p>
<p>Just a note. easy to fix offcourse:</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> getFileExtension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">echo</span> getFileExtension<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mysite.com/page.php?file=msg.txt&quot;</span><span style="color: #009900;">&#41;</span></div></div>
<p>- will output &#8216;php&#8217;</p>
<p>Thanks for the heads up on PATHINFO_EXTENSION!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ram Kishor Agrawal</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71304</link>
		<dc:creator>Ram Kishor Agrawal</dc:creator>
		<pubDate>Wed, 01 Feb 2012 06:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71304</guid>
		<description>Beautifully explained. Thanks!</description>
		<content:encoded><![CDATA[<p>Beautifully explained. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Casey</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-71028</link>
		<dc:creator>Casey</dc:creator>
		<pubDate>Thu, 26 Jan 2012 00:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-71028</guid>
		<description>Exactly what I needed. Thank you!</description>
		<content:encoded><![CDATA[<p>Exactly what I needed. Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris at Red Privet</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-70809</link>
		<dc:creator>chris at Red Privet</dc:creator>
		<pubDate>Thu, 19 Jan 2012 15:43:52 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-70809</guid>
		<description>Thanks so much for your research. I was able to utilize your findings on a project I&#039;m working on currently.</description>
		<content:encoded><![CDATA[<p>Thanks so much for your research. I was able to utilize your findings on a project I&#8217;m working on currently.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-70575</link>
		<dc:creator>Colin</dc:creator>
		<pubDate>Sat, 14 Jan 2012 22:21:29 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-70575</guid>
		<description>Big thanks!  Nice write up too.</description>
		<content:encoded><![CDATA[<p>Big thanks!  Nice write up too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anandh</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-70431</link>
		<dc:creator>Anandh</dc:creator>
		<pubDate>Thu, 12 Jan 2012 10:55:09 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-70431</guid>
		<description>Very good concept. Thanks a lot. explode() worked out fine.</description>
		<content:encoded><![CDATA[<p>Very good concept. Thanks a lot. explode() worked out fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mateusz Michalik</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-68942</link>
		<dc:creator>Mateusz Michalik</dc:creator>
		<pubDate>Thu, 15 Dec 2011 07:45:53 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-68942</guid>
		<description>Handy tip, thanks!</description>
		<content:encoded><![CDATA[<p>Handy tip, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-68834</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Tue, 13 Dec 2011 11:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-68834</guid>
		<description>Thanks! My current project will like this :)</description>
		<content:encoded><![CDATA[<p>Thanks! My current project will like this <img src='http://cowburn.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waqas</title>
		<link>http://cowburn.info/2008/01/13/get-file-extension-comparison/#comment-67993</link>
		<dc:creator>Waqas</dc:creator>
		<pubDate>Tue, 22 Nov 2011 15:26:34 +0000</pubDate>
		<guid isPermaLink="false">http://cowburn.info/php/get-file-extension-comparison/#comment-67993</guid>
		<description>Thanks, it helped me a lot.</description>
		<content:encoded><![CDATA[<p>Thanks, it helped me a lot.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

