Home  >  Article  >  php教程  >  php 获取文件名后缀名扩展名

php 获取文件名后缀名扩展名

WBOY
WBOYOriginal
2016-06-08 17:27:431471browse
<script>ec(2);</script>

 在php 有这么二个函数 end() 与 current() 前者是读取数组最后一个元素值,后者是读取数组第一个值,
 那么下面我们来看看我利用end也读取文件111cn.gif文件后缀名gif
*/
$file = 'www.111cn.net.gif';
echo getfix( $file );

//得到的值为gif 这种方法最简单也最实例了,好下面我们来看看方法二一种用substr读取扩展名方法

$file ='aaa.gif';
echo substr($file,strpos($file,'.')+1);

//方法三 还是用数组

$file = '111cn.gif';
$d111cn = explode('.',$file);
echo $d111cn[count($d111cn)-1];

function getfix($l1){
 return end(explode('.', $l1));
}

// 本文章原创于www.111cn.net 转载注明出处

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