Faster way to get a file extension in PHP

$extension = substr(strrchr($file, "."), 1);

Get the Base name (that has multiple extensions)

$first = current(explode(".", basename($file)));
$path_parts = pathinfo('/www/htdocs/index.html');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0

Leave a Reply

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