What are some best practices for ensuring consistent character encoding between HTTP responses and PHP scripts?

In order to ensure consistent character encoding between HTTP responses and PHP scripts, it is important to set the correct encoding in both the PHP script and the HTTP response headers. This can be achieved by setting the character encoding in the PHP script using the header() function before any output is sent. Additionally, it is recommended to include the charset parameter in the Content-Type header of the HTTP response to specify the character encoding.

<?php
// Set the character encoding in the PHP script
header('Content-Type: text/html; charset=utf-8');

// Output some content
echo "Hello, world!";
?>