title: PHP search result highlight script
body: <p>So let's say I make a search on my website for "Tales of an Ancient Empire".
  My database is doing a full text search, and results come up. I have this function for the highlight thngy</p>
  
  <pre><code>function sublinhamos($text, $words) {
  
      // explode the phrase in words
      $wordsArray = explode(' ', $words); 
  
      // loop all searched words
      foreach($wordsArray as $word) {
          //highlight
          $text = str_ireplace($word, "&lt;span class=\"highlight\"&gt;".strtoupper($word)."&lt;/span&gt;", $text, $count);
      } 
      //right trows results
      return $text;
  }
  </code></pre>
  
  <p>It's not too bad, but the problem here is because the seach terms is "Tales of an Ancient Empire", when the str_ireplace finds the already inserted SPAN's it encounters the "an" words from the search term, and break the SPAN tag.</p>
  
  <p>I need the highlight to highlight parts of a word, and all words up to two characters minimum, but it's all good apart from the old SPAN encounter problem.</p>
  
  <p>Any ideas please?</p>