Hello
I am looking for a good efficient method to extract the file extension in PHP. I have read of various methods using substrings, or splits etc but I want to find the best way to accomplish this.
Thanks
Joe from Rockville
One thought on “What is the best method to extract a file extension in PHP?”
Comments are closed.
Hello Joe
Yes there is in fact a very good method to extract the file extension from PHP called
pathinfo()
.$ext = pathinfo($filename, PATHINFO_EXTENSION);
This is a very reliable built in function that is fast and efficient.
Pathinfo()
is not limited to only providing the file extension but can also provide other information about the file depending on the constant that you pass to it.