How can PHP developers ensure that search terms with special characters, such as umlauts, are properly displayed when using preg_replace for highlighting?

When using preg_replace for highlighting search terms in PHP, special characters such as umlauts may not be properly displayed. To ensure that these special characters are handled correctly, developers can use the 'u' modifier in the preg_replace function, which enables Unicode support.

$search_term = "Möbel";
$text = "Wir verkaufen Möbel für Ihr Zuhause.";
$highlighted_text = preg_replace('/(' . preg_quote($search_term, '/') . ')/iu', '<strong>$1</strong>', $text);
echo $highlighted_text;