How can PHP be used to filter out specific file types from a directory listing?

To filter out specific file types from a directory listing in PHP, you can use the `glob` function to retrieve a list of files in the directory and then use a loop to filter out files with specific extensions. You can achieve this by checking the file extension using the `pathinfo` function and then excluding files with the specified extensions from the final list.

$directory = 'path/to/directory';
$files = glob($directory . '/*');
$allowedExtensions = ['jpg', 'png', 'gif'];

foreach ($files as $file) {
    $extension = pathinfo($file, PATHINFO_EXTENSION);
    if (!in_array($extension, $allowedExtensions)) {
        continue;
    }
    
    echo $file . PHP_EOL;
}