how do i highlight search results from mysql query using php?
this is my [modified] code:
$search_result = \"\";
$search_result = $
you could use preg_replace();, when it finds a match in your text you could place a div with a class of highlight around the matching word. You would then add a background color and border to the highlight class to make it stand out
preg_replace expect 3 parameters;
so for example
<div class="center_div">
<table>
<caption>Search Results</caption>
<?php while ($row= mysql_fetch_array($result)) { ?>
<?php $arabic = preg_replace("/".$search_result."/", "<div class='highlight'>".$search_result."</div>", h($row['cArabic'])); ?>
<tr>
<td style="text-align:right; font-size:15px;"><?php $arabic ?></td>
<td style="font-size:16px;"><?php h($row['cQuotes']) ?></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>
</div>
I only did it for arabic but you might need to do that for cQuotes, vAuthor and vReference as well.
You can do that by using a JavaScript library called HiLite. It works pretty well.