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
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;
}
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.
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.
Any ideas please?