What are best practices for handling character encoding in PHP projects to avoid display issues?

Character encoding issues in PHP projects can lead to display problems such as garbled text or special characters not showing correctly. To avoid these issues, it is important to ensure that the correct character encoding is set in both the PHP files and the HTML output. One common practice is to use UTF-8 encoding, which supports a wide range of characters and symbols.

// Set UTF-8 encoding in PHP
header('Content-Type: text/html; charset=UTF-8');

// Set UTF-8 encoding in HTML output
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">