<?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>Ersin Acar &#187; extension</title>
	<atom:link href="http://ersinacar.com/tag/extension/feed" rel="self" type="application/rss+xml" />
	<link>http://ersinacar.com</link>
	<description>PHP and Web Technologies Freak</description>
	<lastBuildDate>Fri, 14 May 2010 11:57:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to get file extensions in PHP</title>
		<link>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html</link>
		<comments>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html#comments</comments>
		<pubDate>Thu, 21 May 2009 09:22:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[split]]></category>
		<category><![CDATA[strpos]]></category>
		<category><![CDATA[strrchr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=123</guid>
		<description><![CDATA[There are several methods get a file extension using PHP:

&#60;?
$filename = 'myfile.jpg';
&#160;
// 1. The &#34;explode/end&#34; method
$ext = end&#40;explode&#40;'.', $filename&#41;&#41;;
&#160;
// 2. The &#34;strrchr&#34; method
$ext = substr&#40;strrchr&#40;$filename, '.'&#41;, 1&#41;;
&#160;
// 3. The &#34;strrpos&#34; method
$ext = substr&#40;$filename, strrpos&#40;$filename, '.'&#41; + 1&#41;;
&#160;
// 4. The &#34;preg_replace&#34; method
$ext = preg_replace&#40;'/^.*\.([^.]+)$/D', '$1', $filename&#41;;
&#160;
// 5. The &#34;never use this&#34; method
//   From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts [...]]]></description>
			<content:encoded><![CDATA[<p>There are several methods get a file extension using PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'myfile.jpg'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 1. The &quot;explode/end&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 2. The &quot;strrchr&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 3. The &quot;strrpos&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 4. The &quot;preg_replace&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^.*\.([^.]+)$/D'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 5. The &quot;never use this&quot; method</span>
<span style="color: #666666; font-style: italic;">//   From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm</span>
<span style="color: #000088;">$exts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[/<span style="color: #000099; font-weight: bold;">\\</span>.]&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$n</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP find file extension</title>
		<link>http://ersinacar.com/php-find-file-extension_44.html</link>
		<comments>http://ersinacar.com/php-find-file-extension_44.html#comments</comments>
		<pubDate>Tue, 07 Apr 2009 22:49:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=44</guid>
		<description><![CDATA[This simple code example uses a combination of strrchr to find the last occurrence of a string and substr to return part of the string in order to find the file extension for a given filename. This is ideal if you want to quickly find a file extension.

$ext = substr&#40;strrchr&#40;$fileName, '.'&#41;, 1&#41;;

This code can be [...]]]></description>
			<content:encoded><![CDATA[<p>This simple code example uses a combination of strrchr to find the last occurrence of a string and substr to return part of the string in order to find the file extension for a given filename. This is ideal if you want to quickly find a file extension.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This code can be used in the following way.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fileName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'\path\to\file\afile.jpg'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span></pre></div></div>

<p>The output here is &#8216;jpg&#8217;;</p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/php-find-file-extension_44.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
