What is the best way to extract file extensions from file names in PHP?

To extract file extensions from file names in PHP, you can use the built-in pathinfo() function. This function returns an associative array containing information about a file path, including the file extension. You can then access the 'extension' key in the array to get the file extension.

$filename = 'example.txt';
$extension = pathinfo($filename, PATHINFO_EXTENSION);
echo $extension;