how to get file extension from path or url with php?

You can get file extension with the help of pathinfo function. Example:

<?php
$path = "folder/subfolder/myfile.ext";
$path_parts = pathinfo($path);
echo "dirname: ". $path_parts['dirname']."\n"; // will show "folder/subfolder"
echo "basename: ". $path_parts['basename']."\n"; // will show "myfile.ext"
echo "extension: ". $path_parts['extension']."\n"; // will show "ext"
echo "filename: ". $path_parts['filename']."\n"; // will show "myfile"
?>

Results for "folder/subfolder/myfile.ext":

dirname: folder/subfolder
basename: myfile.ext
extension: ext
filename: myfile

Results for "http://www.yourdomain.com/subdir/myfile.ext":

dirname: http://www.yourdomain.com/subdir
basename: myfile.ext
extension: ext
filename: myfile

Google Ads

Valid XHTML 1.0 Strict Valid CSS!