What are best practices for encoding and displaying special characters like Umlaute in PHP applications like MediaWiki?

Special characters like Umlaute (e.g., ä, ö, ü) can be properly encoded and displayed in PHP applications like MediaWiki by ensuring that the encoding is set to UTF-8 and using functions like htmlentities() or htmlspecialchars() to encode the characters before displaying them on the webpage. This helps prevent any potential security vulnerabilities and ensures that the characters are displayed correctly to users.

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

// Encode special characters before displaying
$text = "Umlaute: ä, ö, ü";
echo htmlentities($text, ENT_QUOTES, 'UTF-8');