How to get the extension using php's pathinfo function

不言
Release: 2023-04-04 15:10:01
Original
3959 people have browsed it

The extension is the string after the last (.) in the file path. The pathinfo function can be used to return the file path information, so this article will introduce to you how to obtain the extension by the pathinfo function in PHP.

How to get the extension using How to get the extension using phps pathinfo functions pathinfo function

How to use the pathinfo function

Use the pathinfo function to return information about the file path.

mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )
Copy after login

In path, specify the path to be checked.

In options, you can use constants to specify the elements to be returned. If not specified, all elements are returned.

If options are omitted, the return value is an associative array containing PATHINFO_DIRNAME, PATHINFO_BASENAME and PATHINFO_EXTENSION or PATHINFO_FILENAME. To get the extension, the key will get the value of the extension element.

If only PATHINFO_EXTENSION is specified in options, you can only get the extension string.

Let’s look at a specific example

Get the file path extension through the pathinfo function.

The code is as follows


        
Copy after login

The execution result is displayed as follows:

How to get the extension using How to get the extension using phps pathinfo functions pathinfo function

This article ends here It’s all over. For more exciting content, you can pay attention to the relevant column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to get the extension using php's pathinfo function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!