What are some best practices for handling Umlaut characters in PHP scripts to avoid data corruption?

When handling Umlaut characters in PHP scripts, it is important to ensure that the encoding is consistent throughout the application to avoid data corruption. One best practice is to use UTF-8 encoding for all input/output operations. Additionally, when working with database interactions, make sure the database connection is set to use UTF-8 encoding as well.

// Set UTF-8 encoding for PHP scripts
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');

// Set UTF-8 encoding for database connection
$mysqli = new mysqli("localhost", "username", "password", "database");
$mysqli->set_charset("utf8");