$file = 'example.png'; $extension = pathinfo($file, PATHINFO_EXTENSION); echo $extension;
$file = 'mydocument.pdf'; $extension = pathinfo($file, PATHINFO_EXTENSION); if($extension == 'pdf') { // do something with PDF file }This code checks if the file extension of $file is "pdf" and performs an operation accordingly. This function is part of PHP's core library and does not require any additional package or library.