What precautions should be taken when using special characters like "ö" in preg_match expressions in PHP?

Special characters like "ö" can cause issues when using them in preg_match expressions in PHP because they may not be recognized properly due to character encoding differences. To avoid this problem, it is recommended to use the "u" modifier in the preg_match function to ensure that Unicode characters are properly handled.

$string = "This is a string with special characters like ö";
$pattern = '/ö/u';

if (preg_match($pattern, $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}