How can a function be created in PHP to consistently display error messages in a specific location on a webpage?

To consistently display error messages in a specific location on a webpage in PHP, you can create a function that accepts an error message as a parameter and then echoes out the error message in the desired location on the webpage. This function can be called whenever an error needs to be displayed.

<?php
function displayErrorMessage($message) {
    echo "<div style='color: red;'>$message</div>";
}

// Example usage:
$error = "An error occurred!";
displayErrorMessage($error);
?>