title: Bold matched text in a String in PHP
body: <p>I use the following code for replacing matched words within a String:</p>
  
  <pre><code>for ($i=0; $i &lt; count($terms); $i++) {
      if ( $terms[$i] == '' || $terms[$i] == ' ' || strlen($terms[$i])==0 ) continue;
          $searchingFor     = "/" . $terms[$i] . "/i";
          $replacePattern   = "&lt;strong&gt;$0&lt;/strong&gt;";
          $result['titulo'] = preg_replace($searchingFor, $replacePattern, $result['title']);
  }
  echo $result['title']; 
  </code></pre>
  
  <p>Where 'terms' is an Array from $_GET['terms'].</p>
  
  <p>All works fine except when user input strings containing characters like slashes. It arise an exception in preg_replace.</p>
  
  <p>How can i solve this issue?</p>
  
  <p>Thanks.</p>