How can special characters like ö, ü, ä be handled in PHP when using regular expressions for form validation?

Special characters like ö, ü, ä can be handled in PHP regular expressions by using the 'u' modifier which enables Unicode support. This allows the regular expression engine to correctly match and validate these special characters in form inputs.

// Example of using the 'u' modifier for Unicode support in regular expressions
$input = "München";
$pattern = '/^[a-zA-ZäöüÄÖÜß ]+$/u';

if (preg_match($pattern, $input)) {
    echo "Input is valid.";
} else {
    echo "Input contains invalid characters.";
}