php獲取文件後綴的九種方法

<?php
/**
 * Created by PhpStorm.
 * User: liuft
 * Date: 2016/3/7
 * Time: 15:46
 */php

//第一種
// function get_extension($file)
// {
//     $file = explode('.', $file);
//     return end($file);
// }
//第二種web

// function get_extension($file)
// {
//     return substr(strrchr($file, '.'), 1);
// }orm


//第三種
// function get_extension($file){
//     return pathinfo($file)['extension'];
// }
//get


//第四種
//function get_extension($file)
//{
//    return substr($file, strrpos($file, '.') + 1);
//}it

//第五種
//function get_extension($file)
//{
// $file = preg_split('/\./', $file);
//    return end($file);
//}io


//第六種
// function   get_extension($file){
//     $file = strrev($file);
//     return strrev(substr($file,0,strpos($file,'.')));
// }
//function

//第七種
// 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):'';
// }class


//第九種
// function get_extension($file){
//     return str_replace('.','',strrchr($file,'.'));
// }file


//暫時想這麼多,之後想起來再補充im

$file = "http://10.31.63.8:8081/M00/00/09/Ch8_CFaaMLqAO87JAACePvS0ZRk.webp";

$data = get_extension($file);

var_export($data);

相關文章
相關標籤/搜索