百度
360搜索
搜狗搜索

php中几种获取文件后缀名的方法详细介绍

  php中有多种获取文件后缀名的方法,比如使用substr()函数与pathinfo()函数等,下面就来介绍几种php中获取文件后缀名的方法。

  示例1:

  php substr() 函数获取文件后缀名function get_extension($file){

  return substr(strrchr($file, '.'), 1);

  }

  示例2:function get_extension2($file){

  return substr($file, strrpos($file, '.')+1);

  }

  示例3:

  php explode() 函数获取文件的后缀名function get_extension3($file){

  return end(explode('.', $file));

  }

  示例4:

  php pathinfo() 函数获取文件的后缀名!function get_extension4($file){

  $info = pathinfo($file);

  return $info['extension'];

  }

  示例5:

  php pathinfo() 函数中的第二个参数的值如果为 PATHINFO_EXTENSION ,可以直接返回文件的后缀名!function get_extension5($file){

  return pathinfo($file, PATHINFO_EXTENSION);

  }

阅读更多 >>>  myeclipse设置成中文,myeclipse2014汉化教程

文章数据信息:

本文主要探讨:"php中几种获取文件后缀名的方法", 浏览人数已经达到41次, 首屏加载时间:2.871 秒。