I have a basic php search form that highlights keywords using css. I was interested to know if I can make keywords in the results only when the user hangs over the record. is it possible?
this is the highlight code:
function highlightWords($text, $words) {
preg_match_all('~\w+~', $words, $m);
if(!$m)
return $text;
$re = '~\\b(' . implode('|', $m[0]) . ')~i';
$string = preg_replace($re, '<span class="highlight">$0</span>', $text);
return $string;
}
. . .
<table class="result">
<?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) {
$cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
?>
<tr>
<td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td>
<td style="font-size:16px;"><?php echo $cQuote; ?></td>
<td style="font-size:12px;"><?php h($row['vAuthor']); ?></td>
<td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td>
</tr>
<?php } ?>
</table>
CSS
table.result tr:hover {
background:#F7F7F7;
}
.highlight {
font-weight:bold;
color: #DE2842;
padding:5px;
padding-right:2px;
background: #FFFCDB;
}
I tried to change the color using the highlight: hover over the mouse, but that only changed the color of the search keyword when I was hovering over the keyword, which is understandable, since thatβs how it should work, but I would like the keywords for searches that will be highlighted when I am above the result as a whole.
input source
share