php经典面试题--五种以上方法获取扩展名

来源:互联网 发布:淘宝店铺降权截图 编辑:程序博客网 时间:2024/04/29 02:19
<?php/* * 获取扩展名.jpg或者jpg */function get_ext1($path){$arr = pathinfo($path);return $arr['extension'];}function get_ext2($path){$pos = strrpos($path, '.');return substr($path, $pos);}function get_ext3($path){$arr = explode('.', $path);return  array_pop($arr);}function get_ext4($path){$path = strrev($path);$arr = explode('.', $path);return  strrev($arr[0]);}function get_ext5($file_name){return strrchr($file_name, '.');}function get_ext6($path){ preg_match_all('/\.[^.]*/', $path, $matches); return array_pop($matches[0]);}function get_ext7($path){$path = strrev($path);$pos = strpos($path, '.');return  strrev(substr($path, 0, $pos));}$path = 'c:/cc/cxm/hbt.lhm.jpg';echo get_ext1($path); //输出jpgecho get_ext2($path); //输出.jpgecho get_ext3($path); //输出jpgecho get_ext4($path); //输出jpgecho get_ext5($path); //输出.jpgecho get_ext6($path); //输出.jpgecho get_ext7($path); //输出jpg

原创粉丝点击