How to get the file extension in php, _PHP tutorial

WBOY
Release: 2016-07-12 09:06:28
Original
846 people have browsed it

How to get the extension of a file in php?

There are many similar methods on the Internet, but they all have some imprecise problems. This article will not analyze them one by one. Here Only the most correct method of using php to obtain the file extension (file suffix) is given.

function get_extension($filename){ 
  return pathinfo($filename,PATHINFO_EXTENSION); 
} 
Copy after login

The PHP built-in function pathinfo is used in the function. Let’s analyze the meaning and usage of this function:
Definition and usage
The pathinfo() function returns file path information in the form of an array.
Grammar
pathinfo(path,options)

Description: pathinfo() returns an associative array containing path information. Array elements include the following values:
[dirname]
[basename]
[extension]

For example:

<&#63;php 
print_r(pathinfo("/testweb/test.txt")); 
&#63;> 
Copy after login

The above will output the following Result:

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

The above is the method to correctly use php to obtain the file extension (file suffix name). I hope you like it and apply what you have learned.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1065569.htmlTechArticleHow to get the file extension in php. There are many similar methods on the Internet, but they are all not rigorous in this way. This article will not analyze the problems one by one. Here we only give the most correct benefits...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template