Home  >  Article  >  Backend Development  >  PHP获取文件的扩展名

PHP获取文件的扩展名

WBOY
WBOYOriginal
2016-06-23 13:09:29894browse

<?php   $url = 'dir/upload.image.jpg';      function getExt1($url){      return strrchr($url,'.');   }      function getExt2($url){      return substr($url,strrpos($url,'.'));   }      function getExt3($url){      $a = explode('.',$url);      return array_pop($a);   }      function getExt4($url){      $p = pathinfo($url);      return $p['extension'];   }      function getExt5($url){      return strrev(substr(strrev($url), 0, strpos(strrev($url), '.')));   }      $s = getExt5($url);   echo $s;?>

  

注:1、strrchr() - 函数查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符。否则返回false。

  2、array_pop():删除数组中的最后一个元素。返回值:返回数组的最后一个值。如果数组是空的,或者非数组,将返回 NULL。

  3、pathinfo() 返回一个关联数组包含有 path 的信息。

       包括以下的数组元素:[dirname]、[basename]、[extension]

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