What are the best practices for setting the encoding in PHP to handle special characters effectively?

Special characters can cause encoding issues in PHP if not handled properly. To ensure special characters are displayed correctly, it is best practice to set the encoding to UTF-8. This can be done by setting the default_charset directive in php.ini or using header() function in PHP to set the Content-Type header to include charset=utf-8.

// Set the default encoding to UTF-8 in php.ini
default_charset = "UTF-8";

// Or set the encoding using header() function in PHP
header('Content-Type: text/html; charset=UTF-8');