str_ireplace not working with German characters
I am using the following function to search for words and color them inside a text. It works perfectly except for German characters (ä, ë, ß, etc). I already tried to encode to utf, decode, checked my meta tags and everything else like that but the problem is not the encoding as they show correctly on the site, they're just not "colored" by this function:
function highlight($keyword, $input, $linktext, $color){
$text = $input;
$word = $keyword;
$text = str_ireplace(" ".$word, ' <span id="">' . $word . '</span>', $text);
$iteration = 1;
while (true) {
$text = preg_replace('/<span.id="">' . $word . '<\/span>/imsx开发者_如何学编程U', '<span style="background:'.$color.'" class="keyword" id="link' .
$iteration . "\" onclick=\"setLink2('$keyword','$linktext',$iteration)\">" . $word . '</span>', $text, 1, $count);
if (!$count) {
break;
}
$y++;
$iteration++;
}
return $text;
}
Any idea of how can I achieve this? I also tried to replace them but the German words should apear as they are on the text so that's a no go =/
as str_ functions in PHP do not support UTF, you have to use the mb_ extension. In your case, replace str_ireplace with mb_eregi_replace
精彩评论