treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Find File Extension

Last 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));
}
View Comments

Comments

  1. Permalink to comment#

    I always use latest method

Leave a Comment

Use markdown or basic HTML and be nice.