Hi,
I've got a problem with regular expressions and strings containing
Swedish characters (åäö).
I basically have a PHP script that highlights certain words in a text. I
found the code attached below in the commented manual at php.net. It
works great for all words that do not contain Swedish characters. The
words that do contain åäö will not be highlighted.
Can anyone suggest how I should change my regexp to fix this?
Thanks,
toffe
Code:
=============
function highlightErrors ($text, $errors) {
foreach($errors as $e) {
$text = highlight_word( $text,$e);
}
return $text;
}
function highlight_word( $buff,$query) {
$buff = preg_replace("/(^|[^A-ZåäöÅÄÖ]){1}(".preg_quo te($query,"/").
")($|[^A-ZåäöÅÄÖ]){1}/i",
"\\1<span class='highligh t'>\\2</span>\\3", $buff);
return $buff;
}
=========
I've got a problem with regular expressions and strings containing
Swedish characters (åäö).
I basically have a PHP script that highlights certain words in a text. I
found the code attached below in the commented manual at php.net. It
works great for all words that do not contain Swedish characters. The
words that do contain åäö will not be highlighted.
Can anyone suggest how I should change my regexp to fix this?
Thanks,
toffe
Code:
=============
function highlightErrors ($text, $errors) {
foreach($errors as $e) {
$text = highlight_word( $text,$e);
}
return $text;
}
function highlight_word( $buff,$query) {
$buff = preg_replace("/(^|[^A-ZåäöÅÄÖ]){1}(".preg_quo te($query,"/").
")($|[^A-ZåäöÅÄÖ]){1}/i",
"\\1<span class='highligh t'>\\2</span>\\3", $buff);
return $buff;
}
=========
Comment