PHP 獲取檔案 副檔名 的常用方法小結【五種方式】

Coder199發表於2019-04-15
 
1:
  function getExt1($filename)
  {
     $arr = explode('.',$filename);
     return array_pop($arr);;
  }
 
2:
  
  function getExt2($filename)
  {
     $ext = strrchr($filename,'.');
     return $ext;
  }
3:
  
  function getExt3($filename)
  {
     $pos = strrpos($filename, '.');
     $ext = substr($filename, $pos);
     return $ext;
  }
 
4:
  
  function getExt4($filename)
  {
     $arr = pathinfo($filename);
     $ext = $arr['extension'];
     return $ext;
  }
 
5:
  
  function getExt4($filename)
  {
     $arr = pathinfo($filename);
     $ext = $arr['extension'];
     return $ext;
  }
 

相關文章