Php getting File extension _ PHP Tutorial

Source: Internet
Author: User
Php obtains the file extension. How does php obtain a file extension simply from the end of a file? This can be used with the pathinfo () function, but more importantly, in this case. Although php obtains the file extension
I used to need to get the file extension simply from the end of a file? This can be used with the pathinfo () function, but more

In this case, we need. Although pathinfo () is an extension, it does not return vertices. Think of it

This function was created in an earlier version of php3 for the purpose of maintaining and leaving it to history. Both methods provide

Fun.

/*** Example usage ***/
$ Filename = 'filename.blh.txt ';

/*** Get the path info ***/
$ Info = pathinfo ($ filename );

/*** Show the extension ***/
Echo $ info ['extension'];

?>

The second method is basically the same, but the string operation is also used to obtain the extension and contention point (.) characters.


/*** Example usage ***/
$ Filename = 'filename.blh.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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444987.htmlTechArticlephp to get a file extension once needed to get a file extension simply from the end of a file? This can be used with the pathinfo () function, but more importantly, in this case. Although...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.