Home  >  Article  >  Backend Development  >  php如何获取文件的扩展名,_PHP教程

php如何获取文件的扩展名,_PHP教程

WBOY
WBOYOriginal
2016-07-12 09:06:28732browse

php如何获取文件的扩展名,

网上也有很多类似的方法,不过都存在这样那样的不严谨的问题,本文就不一一分析了,这里只给出最正确的利用php 获取文件扩展名(文件后缀名)的方法。

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

函数中用到了php内置函数pathinfo 这个函数,下面分析一下这个函数的意思和用法:
定义和用法
pathinfo() 函数以数组的形式返回文件路径的信息。
语法
pathinfo(path,options)

说明:pathinfo() 返回一个包含有 path 信息的关联数组。数组元素包括以下值:
[dirname]
[basename]
[extension]

例如:

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

以上将输出如下结果

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

以上就是为大家分享的正确利用php 获取文件扩展名(文件后缀名)的方法,希望大家喜欢,并学以致用。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1065569.htmlTechArticlephp如何获取文件的扩展名, 网上也有很多类似的方法,不过都存在这样那样的不严谨的问题,本文就不一一分析了,这里只给出最正确的利...
Statement:
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