How to find the extension of given file name:
See code below:
$file_name = "sample.jpg";
Output will be: .jpg
I need to find the extension of the file name
Example: If we parse sample.jpg i should return .jpg
How to find the extension of given file name:
See code below:
$file_name = "sample.jpg";
Output will be: .jpg
I need to find the extension of the file name
Example: If we parse sample.jpg i should return .jpg
You can try with explode
$file_name = "sample.jpg";
$pieces = explode(".", $file_name);
echo $pieces[0]; // sample
echo '.'.$pieces[count($pieces)-1]; // .jpg
You can also use this:
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
echo $ext;//jpg
Here one way to find:
<?php
$filename = "sample.txt.jpg";
$ext = substr($filename, strrpos($filename, "."));
echo $ext;
?>