If user inputs words into a textfield to search for,
What is the code for highlighting them in the results page?
Thanks Ahead!
Highlighting search terms
Moderator: General Moderators
Here's an example you should be able to modify to suite:
Code: Select all
<?php
$results = 'one two three four five';
$search = 'three five six';
foreach(explode(' ', $search) as $word){
$results = str_replace($word, '<span style="background-color:#f00">'.$word.'</span>', $results);
}
echo $results;
?>