So, let's say I'm doing a search on my site for "Tales of an Ancient Empire". My database does a full text search and the results appear. I have this function to highlight thngy
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, "<span class=\"highlight\">".strtoupper($word)."</span>", $text, $count); } //right trows results return $text; }
This is not so bad, but the problem here is that the terms seach are βTales of the Ancient Empireβ, when str_ireplace finds an already inserted SPAN, it encounters βaβ words from the search term and breaks the SPAN tag.
I need highlighting to highlight parts of a word, and all words up to two characters are minimal, but all this is different from the old problem with the SPAN problem.
Any ideas please?
source share