Return to Snippet

Revision: 12112
at March 2, 2009 18:17 by gdvickery


Updated Code
$fileExt = pathinfo('myfile.txt', PATHINFO_EXTENSION); // Returns "txt"

Revision: 12111
at March 2, 2009 17:16 by gdvickery


Initial Code
$pathInfo = pathinfo('myfile.ext');
$fileExt = $pathInfo['extension'];

Initial URL

                                

Initial Description
This method is a bit faster and more reliable then using the "explode" method. Works with PHP 4.0.3 and up.

Initial Title
Get file extension in one line

Initial Tags
php, file, extension

Initial Language
PHP