In this code example we will understand how to get file extension in PHP this is very useful when you extract part of the file name like filename, file extension maybe if you want to change the extension of an existing file.

Here is the original file path we will extract the file extension and filename without file extension



$url = '';
$file = file_get_contents($url); // To get file
$name = basename($url); // To get file name
$ext = pathinfo($url, PATHINFO_EXTENSION); // To get extension
$name2 = pathinfo($url, PATHINFO_FILENAME); //  File name without extension

echo $name. "<br>";
echo $ext. "<br> file extension";
echo $name2. " File name without extension <br>";


file extension5554e65275c51f06e1d9055f54a44b96 File name without extension