<?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: How to get a file extension</title>
	<atom:link href="http://www.jasny.net/articles/how-to-get-a-file-extension/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasny.net/articles/how-to-get-a-file-extension/</link>
	<description>Helping you out with PHP &#38; MySQL</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:57:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: MRC</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-338130</link>
		<dc:creator>MRC</dc:creator>
		<pubDate>Wed, 07 Dec 2011 00:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-338130</guid>
		<description>If I&#039;m not mistaken, this is valid for all the languages and cases...
Reverse the string and parse it until the first dot.
Sorry for not posting any examples, but my programming skills are limited.</description>
		<content:encoded><![CDATA[<p>If I&#8217;m not mistaken, this is valid for all the languages and cases&#8230;<br />
Reverse the string and parse it until the first dot.<br />
Sorry for not posting any examples, but my programming skills are limited.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Extract sff for selected IDs into a child sff (version 2) &#171; Open Source Pharmacist</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-336953</link>
		<dc:creator>Extract sff for selected IDs into a child sff (version 2) &#171; Open Source Pharmacist</dc:creator>
		<pubDate>Wed, 17 Aug 2011 11:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-336953</guid>
		<description>[...] sff for selected IDs into a child sff (version&#160;2)I thank Peter Cock, Brad Chapman, and Arnold Daniels for the development of the second [...]</description>
		<content:encoded><![CDATA[<p>[...] sff for selected IDs into a child sff (version&nbsp;2)I thank Peter Cock, Brad Chapman, and Arnold Daniels for the development of the second [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan L Smith</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-214736</link>
		<dc:creator>Nathan L Smith</dc:creator>
		<pubDate>Thu, 18 Feb 2010 22:33:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-214736</guid>
		<description>CommonJS:

From http://wiki.commonjs.org/wiki/Filesystem/A, works on Narwhal:

require(&quot;file&quot;).extension(fileName);</description>
		<content:encoded><![CDATA[<p>CommonJS:</p>
<p>From <a href="http://wiki.commonjs.org/wiki/Filesystem/A" rel="nofollow">http://wiki.commonjs.org/wiki/Filesystem/A</a>, works on Narwhal:</p>
<p>require(&#8220;file&#8221;).extension(fileName);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: satan</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-212150</link>
		<dc:creator>satan</dc:creator>
		<pubDate>Mon, 21 Dec 2009 09:20:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-212150</guid>
		<description>Thanks!  This helped a lot!!</description>
		<content:encoded><![CDATA[<p>Thanks!  This helped a lot!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cully Larson</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-211347</link>
		<dc:creator>Cully Larson</dc:creator>
		<pubDate>Fri, 04 Dec 2009 22:02:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-211347</guid>
		<description>For Perl, you forgot the parens around your match group:

my $ext = ($file_name =~ m/([^.]+)$/)[0];</description>
		<content:encoded><![CDATA[<p>For Perl, you forgot the parens around your match group:</p>
<p>my $ext = ($file_name =~ m/([^.]+)$/)[0];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandor</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-208259</link>
		<dc:creator>Sandor</dc:creator>
		<pubDate>Thu, 01 Oct 2009 13:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-208259</guid>
		<description>So in PERL, would using

$string=  do some /stuff $ENV(&#039;PATH_INFO&#039;)/g;

be a better/safer way to grab an extension or even a whole ?query. Replacing the need for a query and even avoiding loading a perl module like CGI. Hence more security and a so on like:

#!/usr/bin/perl -Tw
use strict;
use warnings;
BEGIN{$SIG{__DIE__} = \&amp;FatalErr} #my dies go to a sub#
$ENV{PATH} = &quot;bin:/usr/bin&quot;;
delete ($ENV{qw(IFS CDPATH BASH_ENV ENV)});
my $string=&quot;&quot;;
$string=  do some /stuff with $ENV(&#039;PATH_INFO&#039;)  /here/;
#sanitize $string here
#split it up as needed..

All vars are now ready...

Prob a one liner that can break up the whole deal after taint.

That was just a quick type so, don&#039;t take it literally, just a concept.

I have a PERL sub I am working on that I would like to share here for help in developing it. Everyone who serves up images could use it when done. I will find the proper category to post it here when I clean it up a bit..</description>
		<content:encoded><![CDATA[<p>So in PERL, would using</p>
<p>$string=  do some /stuff $ENV(&#8216;PATH_INFO&#8217;)/g;</p>
<p>be a better/safer way to grab an extension or even a whole ?query. Replacing the need for a query and even avoiding loading a perl module like CGI. Hence more security and a so on like:</p>
<p>#!/usr/bin/perl -Tw<br />
use strict;<br />
use warnings;<br />
BEGIN{$SIG{__DIE__} = \&amp;FatalErr} #my dies go to a sub#<br />
$ENV{PATH} = &#8220;bin:/usr/bin&#8221;;<br />
delete ($ENV{qw(IFS CDPATH BASH_ENV ENV)});<br />
my $string=&#8221;";<br />
$string=  do some /stuff with $ENV(&#8216;PATH_INFO&#8217;)  /here/;<br />
#sanitize $string here<br />
#split it up as needed..</p>
<p>All vars are now ready&#8230;</p>
<p>Prob a one liner that can break up the whole deal after taint.</p>
<p>That was just a quick type so, don&#8217;t take it literally, just a concept.</p>
<p>I have a PERL sub I am working on that I would like to share here for help in developing it. Everyone who serves up images could use it when done. I will find the proper category to post it here when I clean it up a bit..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandor</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-208256</link>
		<dc:creator>Sandor</dc:creator>
		<pubDate>Thu, 01 Oct 2009 12:50:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-208256</guid>
		<description>Excellent, thank you... Your input here forces me to test all my snippets in Zend studio. What&#039;s the use of having it if I don&#039;t use it! 

As far as the security holes when no extension is present (and other possibilities), I was sanitizing before I got to explode. Chalking up some more time on to the explode method.

Thanks again!</description>
		<content:encoded><![CDATA[<p>Excellent, thank you&#8230; Your input here forces me to test all my snippets in Zend studio. What&#8217;s the use of having it if I don&#8217;t use it! </p>
<p>As far as the security holes when no extension is present (and other possibilities), I was sanitizing before I got to explode. Chalking up some more time on to the explode method.</p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnold Daniels</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-208249</link>
		<dc:creator>Arnold Daniels</dc:creator>
		<pubDate>Thu, 01 Oct 2009 10:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-208249</guid>
		<description>Sandor: Thanks for you input, but please have a closer look at my comment.

Using explode will not work correctly if the file does not have an extension. It will work for &#039;/var/www/someimage.jpg&#039;, but not for &#039;/etc/group&#039;. Please execute the code and see for your self.

Please also note the PATHINFO_% constants. You don&#039;t need to get the whole array and than get the extension part from that.

This is most definitely faster than doing an explode + end, since you don&#039;t need to create an array, which is a relative expensive operation.

&lt;pre lang=&quot;php&quot;&gt;
define(&#039;LOOP&#039;, 10000);

function wasteTime() {
    for ($i=0; $i&lt;LOOP; $i++);
}

function usePathinfo() {
	for ($i=0; $i&lt;LOOP; $i++) pathinfo(&quot;/var/www/image.jpg&quot;, PATHINFO_EXTENSION);
}

function useExplode() {
	for ($i=0; $i&lt;LOOP; $i++) end(explode(&#039;.&#039;, &quot;/var/www/image.jpg&quot;));
}

wasteTime();
usePathinfo();
useExplode();
&lt;/pre&gt;

&lt;a href=&quot;http://www.adaniels.nl/wp-content/uploads/screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio.png&quot; rel=&quot;nofollow&quot;&gt;&lt;img src=&quot;http://www.adaniels.nl/wp-content/uploads/screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio-300x201.png&quot; alt=&quot;screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio&quot; title=&quot;screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio&quot; width=&quot;300&quot; height=&quot;201&quot; class=&quot;alignnone size-medium wp-image-271&quot; /&gt;&lt;/a&gt;

&lt;i&gt;I made a error in the benchmark code. Updated the profiling results&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>Sandor: Thanks for you input, but please have a closer look at my comment.</p>
<p>Using explode will not work correctly if the file does not have an extension. It will work for &#8216;/var/www/someimage.jpg&#8217;, but not for &#8216;/etc/group&#8217;. Please execute the code and see for your self.</p>
<p>Please also note the PATHINFO_% constants. You don&#8217;t need to get the whole array and than get the extension part from that.</p>
<p>This is most definitely faster than doing an explode + end, since you don&#8217;t need to create an array, which is a relative expensive operation.</p>
<pre lang="php">
define('LOOP', 10000);

function wasteTime() {
    for ($i=0; $i<loop ; $i++);
}

function usePathinfo() {
	for ($i=0; $i<LOOP; $i++) pathinfo("/var/www/image.jpg", PATHINFO_EXTENSION);
}

function useExplode() {
	for ($i=0; $i<LOOP; $i++) end(explode('.', "/var/www/image.jpg"));
}

wasteTime();
usePathinfo();
useExplode();
</pre>
<p><a href="http://www.adaniels.nl/wp-content/uploads/screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio.png" rel="nofollow"><img src="http://www.adaniels.nl/wp-content/uploads/screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio-300x201.png" alt="screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio" title="screenshot-php-profile-q-demos-benchmark-extensionphp-zend-studio" width="300" height="201" class="alignnone size-medium wp-image-271" /></a></p>
<p><i>I made a error in the benchmark code. Updated the profiling results</i></loop></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandor</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-208227</link>
		<dc:creator>Sandor</dc:creator>
		<pubDate>Wed, 30 Sep 2009 19:28:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-208227</guid>
		<description>end(explode works quite well as posted. Without the &quot;end&quot; you will get the undesired result mentioned above. 

Here is some info on explode and also has an example of the end(explode method that shows that it does work quite well.

http://us3.php.net/manual/en/function.explode.php#87049

My expertise quite limited. Been writing in php off and on only about 5 years now. The explode method works for me though in many ways.

The goal was to return the extension of a file name. Just like the examples at the top of the page here.  Right?

That explode example will do just that. I use it all the time in my snippets. Efficiency is relative to the end app I guess though.

$file = &quot;someimage.jpg&quot;; //or even some.image.jpg

$extension = end(explode(&#039;.&#039;, $file));

outputs  jpg 

// It does everything after the last &#039;.&#039;

I was told by many it is the most efficient way to grab a file name extension with php. If there is a way that uses less resources, I will use it instead. 

Using pathinfo:

$path_parts = pathinfo(&#039;/www/index.html&#039;);

Enables me to:

echo $path_parts[&#039;dirname&#039;], &quot;\n&quot;;
echo $path_parts[&#039;basename&#039;], &quot;\n&quot;;
echo $path_parts[&#039;extension&#039;], &quot;\n&quot;;
echo $path_parts[&#039;filename&#039;], &quot;\n&quot;;

I &quot;think&quot; pathinfo uses more &quot;resources&quot; than just getting the specific result as I did in the explode example.  I could be very wrong. If someone could prove one is method &quot;better&quot; that the other, I will use the better one for sure! I also become concerned about security. The explode method exposes more by far. But it is php. ;-)

Now, in cases where you need to break a file name up, do some pattern matching or directory creation then reconstruct it all later for some reason or another, pathinfo has everything you need all ready and waiting. I use it for that frequently. But, when I don&#039;t, I use the explode method to grab parts of a string or file. When I actually write apps in php that is.. 


Great topic. So many ways to perform a seemingly simple task. But, just because it is simple does not mean it is easy!

Thanks guys!</description>
		<content:encoded><![CDATA[<p>end(explode works quite well as posted. Without the &#8220;end&#8221; you will get the undesired result mentioned above. </p>
<p>Here is some info on explode and also has an example of the end(explode method that shows that it does work quite well.</p>
<p><a href="http://us3.php.net/manual/en/function.explode.php#87049" rel="nofollow">http://us3.php.net/manual/en/function.explode.php#87049</a></p>
<p>My expertise quite limited. Been writing in php off and on only about 5 years now. The explode method works for me though in many ways.</p>
<p>The goal was to return the extension of a file name. Just like the examples at the top of the page here.  Right?</p>
<p>That explode example will do just that. I use it all the time in my snippets. Efficiency is relative to the end app I guess though.</p>
<p>$file = &#8220;someimage.jpg&#8221;; //or even some.image.jpg</p>
<p>$extension = end(explode(&#8216;.&#8217;, $file));</p>
<p>outputs  jpg </p>
<p>// It does everything after the last &#8216;.&#8217;</p>
<p>I was told by many it is the most efficient way to grab a file name extension with php. If there is a way that uses less resources, I will use it instead. </p>
<p>Using pathinfo:</p>
<p>$path_parts = pathinfo(&#8216;/www/index.html&#8217;);</p>
<p>Enables me to:</p>
<p>echo $path_parts['dirname'], &#8220;\n&#8221;;<br />
echo $path_parts['basename'], &#8220;\n&#8221;;<br />
echo $path_parts['extension'], &#8220;\n&#8221;;<br />
echo $path_parts['filename'], &#8220;\n&#8221;;</p>
<p>I &#8220;think&#8221; pathinfo uses more &#8220;resources&#8221; than just getting the specific result as I did in the explode example.  I could be very wrong. If someone could prove one is method &#8220;better&#8221; that the other, I will use the better one for sure! I also become concerned about security. The explode method exposes more by far. But it is php. <img src='http://www.jasny.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Now, in cases where you need to break a file name up, do some pattern matching or directory creation then reconstruct it all later for some reason or another, pathinfo has everything you need all ready and waiting. I use it for that frequently. But, when I don&#8217;t, I use the explode method to grab parts of a string or file. When I actually write apps in php that is.. </p>
<p>Great topic. So many ways to perform a seemingly simple task. But, just because it is simple does not mean it is easy!</p>
<p>Thanks guys!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnold Daniels</title>
		<link>http://www.jasny.net/articles/how-to-get-a-file-extension/comment-page-1/#comment-208217</link>
		<dc:creator>Arnold Daniels</dc:creator>
		<pubDate>Wed, 30 Sep 2009 15:46:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=84#comment-208217</guid>
		<description>Using explode won&#039;t give you the wanted result:

$file = &quot;/etc/passwd&quot;;
$extension = end(explode(’.&#039;, $file));
echo $extension; // Outputs &#039;/etc/passwd&#039;

For PHP use pathinfo() as described in the above article.</description>
		<content:encoded><![CDATA[<p>Using explode won&#8217;t give you the wanted result:</p>
<p>$file = &#8220;/etc/passwd&#8221;;<br />
$extension = end(explode(’.&#8217;, $file));<br />
echo $extension; // Outputs &#8216;/etc/passwd&#8217;</p>
<p>For PHP use pathinfo() as described in the above article.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
