PHP method for obtaining file extension (suffix)

Source: Internet
Author: User
This article will summarize how php gets the file extension, that is, the file suffix. Here, we only provide the most correct method to use php to obtain the file extension (file suffix. Functionget_extension ($ filename) {returnpathinfo ($ filename, PATHINFO_EXTENSION);} the php built-in function pathinfo is used in the function. The following describes the meaning and usage of this function: this article will summarize how php gets the file extension, that is, the file extension name. Here, we only provide the most correct method to use php to obtain the file extension (file suffix.
function get_extension($filename){
return pathinfo($filename,PATHINFO_EXTENSION);

}

The php built-in function pathinfo is used in the function. The following describes the meaning and usage of this function: the definition and usage of pathinfo () function returns the file path information in an array.

Syntax

Pathinfo (path, options)

Parameters Description
Path Required. Specifies the path to be checked.
Process_sections

Optional. Specifies the array element to be returned. The default value is all.

Possible values:

  • PATHINFO_DIRNAME-returns only dirname
  • PATHINFO_BASENAME-only return basename
  • PATHINFO_EXTENSION-returns only extension

For example:

print_r(pathinfo("/testweb/test.txt"));

?>

The following result is output:

Array (

[Dirname] =>/testweb
[Basename] => test.txt
[Extension] => txt
)

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.