php Get file extension_PHP tutorial

WBOY
Release: 2016-07-20 11:07:08
Original
862 people have browsed it

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 ** */

$info = pathinfo($filename);


/*** show the extension ***/

echo $info['extenstion'];


?>

The second method is basically the same as above, but uses string manipulation to get extensions and grab dot (.) characters also.


/*** example usage ***/

$filename = 'filename.blah.txt';


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

truehttp: //www.bkjia.com/PHPjc/444987.htmlTechArticlephp Getting 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template