This article mainly introduces several common methods for PHP to get the file suffix, and analyzes the implementation skills of php to get the file suffix through three different methods, it is implemented through strings, file attributes, and arrays.
This article mainly introduces several common methods for PHP to get the file suffix, and analyzes the implementation skills of php to get the file suffix through three different methods, it is implemented through strings, file attributes, and arrays.
This example describes several common methods for obtaining file extensions in PHP. Share it with you for your reference. The details are as follows:
Method 1:
Function get_file_type ($ filename) {$ type = substr ($ filename, strrpos ($ filename, ".") + 1); return $ type ;}
Method 2:
Function get_file_type ($ filename) {$ type = pathinfo ($ filename); $ type = strtolower ($ type ["extension"]); return $ type ;}
Method 3:
Function get_file_type ($ filename) {$ type = explode (".", $ filename); $ count = count ($ type)-1; return $ type [$ count];}
I hope this article will help you with php programming.
,