What are common pitfalls to avoid when handling character encoding in PHP scripts for MediaWiki?

Common pitfalls to avoid when handling character encoding in PHP scripts for MediaWiki include not setting the correct character encoding in the script, not properly sanitizing input data, and not using the correct functions for encoding and decoding strings.

// Set the correct character encoding
header('Content-Type: text/html; charset=utf-8');

// Sanitize input data
$input = htmlspecialchars($_POST['input'], ENT_QUOTES, 'UTF-8');

// Use the correct functions for encoding and decoding strings
$encoded_string = mb_convert_encoding($string, 'UTF-8');
$decoded_string = mb_convert_encoding($encoded_string, 'ISO-8859-1', 'UTF-8');