Hello,
I have a PHP/MySQL based Web application, that has a search feature.
The client would like the word that the visitor entered in the Search box highlighted in the results.
Any idea on how to achieve this?
Hello,
I have a PHP/MySQL based Web application, that has a search feature.
The client would like the word that the visitor entered in the Search box highlighted in the results.
Any idea on how to achieve this?
Thanks!!
Also you can try to do this with javascript
http://www.tripbase.com/code/highlightTutorial.html
http://eriwen.com/javascript/highlight-search-results-with-js/
http://weblogtoolscollection.com/archives/2009/04/10/how-to-highlight-search-terms-with-jquery/
http://stackoverflow.com/questions/2500987/jquery-highlighting-a-live-search-result
A simple way …
$strg = "Some string containing the character to be highlighted";
$high = "character";
$repl = '<span class="highlight">' . $high . '</span>';
$out = str_replace($high, $repl, $strg);
echo '<p>' . $out . '</p>;
The class “highlight” would contain styles to determine HOW the highlighting is done. e.g.
.highlight {
font-weight: bold; // Bold text
color: #FF0000; // Text color red
}
preg_replace() is another function to consider.