What are the best practices for ensuring consistent character encoding in PHP scripts and web pages?

Consistent character encoding in PHP scripts and web pages can be ensured by setting the appropriate encoding in both the PHP script and the HTML document. This can be achieved by specifying the UTF-8 encoding in the header of the PHP script and using the meta tag in the HTML document. Additionally, using functions like mb_internal_encoding() and mb_http_output() can help maintain consistent character encoding throughout the script.

<?php
// Set UTF-8 encoding in PHP script
header('Content-Type: text/html; charset=UTF-8');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<!-- Your HTML content here -->
</body>
</html>