這篇文章主要介紹了PHP實現獲取文件后綴名的幾種常用方法,通過三種不同的方法實例分析了php獲取文件后綴名的實現技巧,分別通過字符串、文件屬性及數組等方式實現這一功能,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了PHP實現獲取文件后綴名的幾種常用方法。分享給大家供大家參考。具體如下:
方法1:
- function get_file_type($filename){
- $type = substr($filename, strrpos($filename, ".")+1);
- return $type;
- }
方法2:
- function get_file_type($filename)
- {
- $type = pathinfo($filename);
- $type = strtolower($type["extension"]);
- return $type;
- }
方法3:
- function get_file_type($filename)
- {
- $type =explode("." , $filename);
- $count=count($type)-1;
- return $type[$count];
- }
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答