Get file extension program code in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:14:45
Original
872 people have browsed it

Sometimes we want to get the extension of the uploaded file in PHP. Below I will summarize the methods of obtaining the extension in PHP. Friends in need can refer to it.

Method 1, my best way to get extensions

The code is as follows
 代码如下 复制代码

function extend_2($file_name)
{
$extend = pathinfo($file_name);
$extend = strtolower($extend["extension"]);
return $extend;
}

Copy code

 代码如下 复制代码

function get_extension($file)
{
return end(explode('.', $file));
}

function extend_2($file_name)

{
$extend = pathinfo($file_name);

$extend = strtolower($extend["extension"]);
 代码如下 复制代码

function get_extension($file)
{
substr(strrchr($file, '.'), 1);
}

return $extend;

}

Method 2, use the explode function and end function combination operation
The code is as follows

Copy code
function get_extension($file) { return end(explode('.', $file)); } Method three is the same as getting the extension in asp before.
The code is as follows Copy code
function get_extension($file)
{ substr(strrchr($file, '.'), 1); } Well, there are only three methods, which basically satisfy you to obtain the file extension. http://www.bkjia.com/PHPjc/628928.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628928.htmlTechArticleSometimes we want to get the extension of the uploaded file in php. Below I will summarize how to get the extension in php. Summary of methods, friends in need can refer to it. Method 1, my best way to get...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!