Can you provide a step-by-step tutorial or script for implementing an error handler in PHP for displaying error messages in HTML code?

When developing a PHP application, it's important to have a robust error handling system in place to display meaningful error messages to users. One way to achieve this is by using a custom error handler function that captures any PHP errors, warnings, or notices and displays them in a user-friendly format within the HTML code.

```php
// Define custom error handler function
function customErrorHandler($errno, $errstr, $errfile, $errline) {
    echo "<div style='background-color: #ffcccc; color: #cc0000; padding: 10px; margin: 10px;'>Error: [$errno] $errstr in $errfile on line $errline</div>";
}

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

// Trigger an error to test the custom error handler
echo $undefinedVariable;
```

In the above code snippet, we define a custom error handler function `customErrorHandler` that takes four parameters - error number, error message, error file, and error line. Within this function, we echo out a formatted error message using HTML styling. We then use `set_error_handler` to set this custom error handler function as the default error handler for PHP. Finally, we trigger an error by trying to echo an undefined variable to test our custom error handler.