This is the long awaited replacement code for the searchword highlighting in showthreaded.pl.
We are running a much improved search engine, but I downgraded the code so that it should be running with the standard version:
[]/testimages/icons/smile.gif[/]
# highlight the search words in non-html part of post if we came from the search engine
if ($search eq "true") {
my $searchwords = $FORM{'Words'};
my @searchwords = split(/ +/, $searchwords);
# sort the searchwords by size (longest first)
@searchwords = sort( { -(length($a) <=> length($b)) } @searchwords);
my $regexp;
for my $i (0 .. $#searchwords) {
$word = $searchwords[$i];
if (!$word) { next }
# escape *?.+\[]()^|{}$ for use in a regexp
$word =~ s/([\*\?\.\+\\\[\]\(\)\^\|\{\}\$])/\\$+/g;
if ($regexp) { $regexp .= "|" }
$regexp .= "($word)";
}
$regexp = "($regexp)";
# split the body into plain text and html and highlight
my $body;
for (my $i; ; $i++) {
$Body =~ m/([^<]*)((<.*?>)*)/g;
my $plain = $1;
my $html = $2;
if (!$plain && !$html) { last }
$plain =~ s/$regexp/<b><font color="$theme{'search_words'}">$+<\/font><\/b>/gi;
$body .= $plain . $html;
}
$Body = $body;
}