Can anybody say me why doesn't this work for unicode strings preg_replace('/\b'.$word.'\b/ui', '<span class="bigger">$0</span>', $text); Code (markup): The variables $word and $text are unicode strings.
hmmm, firstly you need to convert your document to utf-8 or put this code between HEAD tags up in your page.. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> HTML: then try this sample: $word = 'имÑ'; $text = 'Мое Ð¸Ð¼Ñ Ð ÑƒÐ±ÐµÐ½'; echo preg_replace('/'.$word.'/i', 'your replacement words', $text); PHP: Rep me up if that helps
My document is utf-8 and the meta tag is put. And the code you have written is not what I want. I want to replace that words, which are not in other word-form. For example the word "body" must not be replaced in word "everybody".
you can add whatever you want to the pattern i.e: preg_replace('/ '.$word.'(.|,| |)/i', ' blah ', $text);
And this doesn't work for this $word = "word"; $text = "word word. word word, word"; Try and see that several "word"-s wouldn't be replaced!!! The script that I have written in the first post works perfectly, but not for Unicode strings!!!