How can include() be utilized to display a custom error page in PHP when a file is not found?
When a file is not found in PHP, you can utilize the include() function to display a custom error page instead of the default server error message. By using a conditional statement to check if the file exists before including it, you can redirect to a custom error page if the file is not found. This helps provide a better user experience by showing a more informative error message.
<?php
$file = 'file_to_include.php';
if (file_exists($file)) {
include($file);
} else {
include('error_page.php');
}
?>