如何用php获取文件后缀的几种方法Php

印迹发布于:2019-2-21 1079

<?php
//第一种
 function get_extension($file)
 {
 $file = explode('.', $file);
   return end($file);
 }
//第二种
 function get_extension($file)
 {
   return substr(strrchr($file, '.'), 1);
 }
第三种
 function get_extension($file){
 return pathinfo($file)['extension'];
}
//第四种
function get_extension($file)
{
  return substr($file, strrpos($file, '.') + 1);
} 
//第五种
function get_extension($file)
{
$file = preg_split('/\./', $file);
 return end($file);
}
//第六种
function  get_extension($file){
$file = strrev($file);
  return strrev(substr($file,0,strpos($file,'.')));
}
//第七种
function get_extension($file)
{
  return pathinfo($file, PATHINFO_EXTENSION);
}
//第八种
function get_extension($file)
 {
  preg_match_all('/\.[a-zA-Z0-9]+/',$file,$data);
  return !empty($data[0])?substr(end($data[0]),1):'';
}
//第九种
function get_extension($file){
return str_replace('.','',strrchr($file,'.'));
}
//暂时这么多,以后再补充
$file = "http://10.229.211.123:8081/M00/00/09/Ch8_CFaaMLqAO87JAACePvS0ZRk.webp";
$data = get_extension($file);
var_export($data);


http://www.virplus.com/thread-119.htm

转载请注明:2019-2-21 于 VirPlus 发表

推荐阅读
最新回复 (0)

    ( 登录 ) 后,可以发表评论!

    返回