0

I have the following function that allows me to highlight a word.

function highlight($text, $word) {
    preg_match_all('~\w+~', $word, $m);
    if(!$m) return $text;
    $re = '~\\b(' . implode('|', $m[0]) . ')\\b~i';
    return preg_replace($re, '<mark>$0</mark>', $text);
}

The problem is that it dosen't highlight Swedish characters, like Åå, Ää, and Öö. But if I remove both of the ~ from the regex, it will accept the Swedish characters on Debuggex.

But when I try to run it through my website, I'll get this error message: Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in ... on line 56, which is this line: preg_match_all('\w+', $word, $m);.

How can I make it highlight Swedish characters and also work on my website with it?

Airikr
  • 6,258
  • 15
  • 59
  • 110

0 Answers0