php get file extension
Ever needed to get the file extension simply from the end of a file? This can be done with the pathinfo() function, but more
is needed in this case as well. Although pathinfo() is an extension, it does not return the point. Thinking that this function was created in an early version of php3, it is maintained and left to historical purposes. Both methods provide
fun.
/*** example usage ***/
$filename = 'filename.blah.txt';
/*** get the path info ** */
/*** show the extension ***/
?>
The second method is basically the same as above, but uses string manipulation to get extensions and grab dot (.) characters also.
echo getFileExtension( $filename);
/**
** @Get File extension from file name
*
* @param string $filename the name of the file
*
* @return string
*
**/
function getFileExtension($filename){
return substr($filename, strrpos($filename, '.'));
}
?>
http://www.bkjia.com/PHPjc/444987.html