How can the code snippet provided be improved to handle the situation where a requested file is not found in PHP?

When a requested file is not found in PHP, it is important to handle this situation gracefully to prevent errors or unexpected behavior. One way to improve the code snippet is to check if the file exists before attempting to include it. If the file is not found, an error message or a default file can be displayed instead.

<?php
$file = 'example.txt';

if (file_exists($file)) {
    include $file;
} else {
    echo "File not found.";
}
?>