Use the pathinfo()
function:
$path_parts = pathinfo('/www/htdocs/index.html');
echo $path_parts['dirname'], "
";
echo $path_parts['basename'], "
";
echo $path_parts['extension'], "
";
echo $path_parts['filename'], "
";
or simply:
echo pathinfo($file, PATHINFO_EXTENSION);
You can of course look for the last "." in the filename and get everything after (relatively easy) but why reinvent the wheel?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…