How to obtain the file extension in php? _ PHP Tutorial

Source: Internet
Author: User
How does php obtain the file extension ,. There are many similar methods on the Internet for php to obtain the file extension. However, this is an issue that is not rigorous, so I will not analyze it one by one, here, we only provide the most correct method for obtaining the file extension in php,

There are also a lot of similar methods on the Internet, but there are such a not rigorous problem, this article will not be analyzed one by one, here only gives the most correct use of php to get 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:
Definition and usage
The pathinfo () function returns the file path information in an array.
Syntax
Pathinfo (path, options)

Note: pathinfo () returns an associated array containing path information.The array elements include the following values:
[Dirname]
[Basename]
[Extension]

For example:

<?php print_r(pathinfo("/testweb/test.txt")); ?> 

The output is as follows:Result:

Array( [dirname] => /testweb [basename] => test.txt [extension] => txt)

The above is the correct way to use php to obtain the file extension (file suffix). I hope you will like it and learn how to use it.

There are a lot of similar methods on the Internet, but there are such a not rigorous problem, this article will not be analyzed one by one, here only give the most correct benefits...

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.