Jump to content

highlighting background behind search term in results


dannyb785

Recommended Posts

I've got a search page that spits out results that match the term that was input. Within the results, I want to add a span with a yellow background behind just the search term. I'll show my code, then say my problem

 

<?php
$search = (term in $_GET variable that was searched for);
// while loop that goes through all results, $result is the text that the searched term was found in
  $new_result = str_ireplace($search, "<span style='background:yellow'>$search</span>", $result);
  echo $new_result;
// end while loop
?>

 

my problem is that if somebody searches for the word "bob", then if the term "Bob" was found, when it outputs the $new_result, it shows as "bob" with the yellow background. Searching for "Bob" would give the correct results("Bob" with a yellow background), but basically when the output is given, the case of each letter is displayed as it was typed in the search field.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.