>  기사  >  php教程  >  파일 접미사를 얻는 9가지 방법

파일 접미사를 얻는 9가지 방법

大家讲道理
大家讲道理원래의
2016-11-08 13:35:051453검색

<?php
/**
 * Created by PhpStorm.
 * User: liuft
 * Date: 2016/3/7
 * Time: 15:46
 */
 
//第一种
// function get_extension($file)
// {
//  $file = explode(&#39;.&#39;, $file);
//     return end($file);
// }
//第二种
 
// function get_extension($file)
// {
//     return substr(strrchr($file, &#39;.&#39;), 1);
// }
 
 
//第三种
// function get_extension($file){
//  return pathinfo($file)[&#39;extension&#39;];
// }
//
 
 
//第四种
//function get_extension($file)
//{
//    return substr($file, strrpos($file, &#39;.&#39;) + 1);
//}
 
//第五种
//function get_extension($file)
//{
//  $file = preg_split(&#39;/\./&#39;, $file);
//    return end($file);
//}
 
 
//第六种
// function   get_extension($file){
//  $file = strrev($file);
//     return strrev(substr($file,0,strpos($file,&#39;.&#39;)));
// }
//
 
//第七种
// function get_extension($file)
// {
//     return pathinfo($file, PATHINFO_EXTENSION);
// }
//
//第八种
// function get_extension($file)
// {
//      preg_match_all(&#39;/\.[a-zA-Z0-9]+/&#39;,$file,$data);
//      return !empty($data[0])?substr(end($data[0]),1):&#39;&#39;;
// }
 
 
//第九种
// function get_extension($file){
//     return str_replace(&#39;.&#39;,&#39;&#39;,strrchr($file,&#39;.&#39;));
// }
 
 
//暂时想这么多,以后想起来再补充
 
$file = "http://10.31.63.8:8081/M00/00/09/Ch8_CFaaMLqAO87JAACePvS0ZRk.webp";
 
$data = get_extension($file);
 
var_export($data);

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.