title: Preg_Replace and UTF8
body: <p>I'm enhancing our <a href="http://www.mojvideo.com/tag/judas%20priest/" rel="noreferrer">video search page</a> to highlight the search term(s) in the results. Because user can enter <code>judas priest</code> and a video has <code>Judas Priest</code> in it's text I have to use regular expressions to preserve the case of the original text.</p>
  
  <p>My code works, but I have problems with special characters like <code>š, č and ž</code>, it seems that <code>Preg_Replace()</code> will only match if the case is the same (despite the <code>/ui</code> modifier).
  My code:</p>
  
  <pre><code>$Content = Preg_Replace ( '/\b(' . $term . '?)\b/iu', '&lt;span class="HighlightTerm"&gt;$1&lt;/span&gt;', $Content );
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>$Content = Mb_Eregi_Replace ( '\b(' . $term . '?)\b', '&lt;span class="HighlightTerm"&gt;\\1&lt;/span&gt;', $Content );
  </code></pre>
  
  <p>But it also doesn't work. It will match "SREČA" if the search term is "SREČA", but if the search term is "sreča" it will not match it (and vice versa).</p>
  
  <p>So how do I make this work?</p>
  
  <p><strong>update:</strong> I set the locale and internal encoding:</p>
  
  <pre><code>Mb_Internal_Encoding ( 'UTF-8' );
  $loc = "UTF-8";
  putenv("LANG=$loc");
  $loc = setlocale(LC_ALL, $loc);
  </code></pre>