How to get first file extension in string using PHP? : <p>I want to get first file extension in string using php.</p>

<p>now i use this code.</p>

<pre><code>&lt;?php
$string = "aaa.jpgbbb.pngccc.jpg";
if( strpos( $string, $needle ) !== false ) {
    list($string) = explode('.png',$string);
    echo $string.".jpg";
}
?&gt;
</code></pre>

<p>My code only check file extension in string. but can not get first file extension. How can i do ?</p>

<p>.
.</p>

<p>For this string first file extension is <code>jpg</code>.</p>

<pre><code>$string = "aaa.jpgbbb.pngccc.jpg";
</code></pre>

<p>.
.</p>

<p>For this string first file extension is <code>gif</code>.</p>

<pre><code>$string = "aaa.gifbbb.pngccc.jpg";
</code></pre>

<p>.
.</p>

<p>For this string first file extension is <code>png</code>.</p>

<pre><code>$string = "aaa.pngbbb.pngccc.jpg";
</code></pre>
