//第1種方法: function get_extension($file) { substr(strrchr($file, '.'), 1); } //第2種方法: function get_extension($file) { return substr($file, strrpos($file, '.')+1); } //第3種方法: function get_extension($file) { return end(explode('.', $file)); } //第4種方法: function get_extension($file) { $info = pathinfo($file); return $info['extension']; } //第5種方法: function get_extension($file) { return pathinfo($file, PATHINFO_EXTENSION); }
轉摘https://www.jianshu.com/p/8da4e7e5bd15