How can proper character encoding be ensured in PHP to display special characters like ÄÖÜäöü correctly in form inputs and outputs?
To ensure proper character encoding in PHP for special characters like ÄÖÜäöü, you can set the character encoding to UTF-8 using the header() function and ensure that your HTML document also specifies UTF-8 encoding. Additionally, you can use htmlspecialchars() function when displaying user input to prevent XSS attacks and properly encode special characters.
<?php
header('Content-Type: text/html; charset=utf-8');
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$input = $_POST['input']; // Assuming input is from a form submission
echo htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
?>