How can you query a file extension in PHP?

To query a file extension in PHP, you can use the pathinfo() function to get information about a file path, including the file extension. This function returns an associative array with elements like 'dirname', 'basename', 'extension', and 'filename'. By accessing the 'extension' element of the array, you can retrieve the file extension.

$file_path = 'example.txt';
$file_extension = pathinfo($file_path, PATHINFO_EXTENSION);

echo "The file extension is: $file_extension";