Find File Extension

Avatar of Chris Coyier
Chris Coyier on (Updated on )

Method 1

function findexts ($filename) {

       $filename = strtolower($filename) ;

       $exts = split("[/\\.]", $filename) ;

       $n = count($exts)-1;

       $exts = $exts[$n];

       return $exts;

}

Method 2

$filename = 'mypic.gif';
$ext = pathinfo($filename, PATHINFO_EXTENSION);

Method 3

function getFileextension($file) {
       return end(explode(".", $file));
}