How can PHP errors be automatically logged within a project and displayed in a specific format?

To automatically log PHP errors within a project and display them in a specific format, you can utilize PHP's error handling functions like `set_error_handler()` to capture errors and log them to a file. You can also customize the error messages by creating a function that formats the error information before logging it.

// Custom error handler function
function customErrorHandler($errno, $errstr, $errfile, $errline) {
    $error_message = "Error: [$errno] $errstr in $errfile on line $errline";
    
    // Log error to a file
    error_log($error_message, 3, "error.log");
    
    // Display error in a specific format
    echo "<div style='color: red; font-weight: bold;'>$error_message</div>";
}

// Set custom error handler
set_error_handler("customErrorHandler");