How to get file extension in php ?

In this article, We’ll see how to get file extension in php.

We’ll use pathinfo() function to get the file extension.

pathinfo() function returns information about a file path: either an associative array or a string, depending on options.




Below an example:

 $filename = "report.xls";
 $ext = pathinfo($filename, PATHINFO_EXTENSION);
 echo $ext; // Output xls

That’s it!. Please share your thoughts or suggestions in the comments below.

Posted in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *