Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.