This article mainly introduces how php obtains the file extension, that is, the file extension method, to make a summary. if you are interested, you can refer to it. There are also a lot of similar methods on the Internet, but there are such a not rigorous problem, this article will not be analyzed one by one, here only gives the most correct use of php to get the file extension (file suffix).
Function get_extension ($ filename) {return pathinfo ($ filename, PATHINFO_EXTENSION );}
The php built-in function pathinfo is used in the function. The following describes the meaning and usage of this function:
Definition and usage
The pathinfo () function returns the file path information in an array.
Syntax
Pathinfo (path, options)
Note: pathinfo () returns an associated array containing path information.The array elements include the following values:
[Dirname]
[Basename]
[Extension]
For example:
<? Php print_r (pathinfo ("/testweb/test.txt");?>
The output is as follows:Result:
Array ([dirname] =>/testweb [basename] => test.txt [extension] => txt)
The above is the correct way to use php to obtain the file extension (file suffix). I hope you will like it and learn how to use it.