How can the file extension be extracted from a file name in PHP, especially when the file name may contain periods?
When extracting a file extension from a file name in PHP, especially when the file name may contain multiple periods, we can use the pathinfo() function. This function returns an array containing information about a file path, including the file extension. By accessing the 'extension' key in the returned array, we can easily extract the file extension.
$filename = "example.file.name.txt";
$extension = pathinfo($filename, PATHINFO_EXTENSION);
echo $extension;