Get file extension
This function works correct with files with no extension.
Copy this code and paste it in your HTML
function getExtension($filename)
{
return ('.' . ($ext = pathinfo($filename, PATHINFO_EXTENSION
)) == $filename) ?
null : $ext; }
// Example:
var_dump(getExtension
('.htaccess'), getExtension
('image.jpg')); // Result:
// NULL
// string(3) "jpg"
Report this snippet
Comments
Subscribe to comments