Browse - Programming Tips - php: get file extension

Date: 2018sep6
Language: php
Keywords: suffix

Q.  php: get file extension

A.

function getExt($file) { if (($i = strrpos($file, '.')) === false) return ''; return substr($file, $i + 1); }
Using pathinfo() is the offical way but I prefer the above
function getExt2($file) { return pathinfo($file, PATHINFO_EXTENSION); }