Jump to content

[SOLVED] Highlighting of a search term in search results


steve m

Recommended Posts

Hello,

I am writing this simple MySQL and PHP search and what I want to do is to highlight the search term in the results when they are displayed on the screen.  I am able to get it to work. but the seach term will only be highlighted(Make it Bold) only if it matches exactly to what was typed in the search box.  Is there a way where the search term doesn't have to exactly match in order for it to be highlighted?  Below is the code where I change the the search term into bold to be displayed on the screen.

<?php
$result_manufact = str_replace($splitstr, "<span style=\"color: red; font-weight: bold;\">$splitstr</span>", $manufact);
?> 

Link to comment
Share on other sites

No, I wasn't thinking of a Fuzzy Search.  It just a search in one table and it just splits up the phrases (if any) and searches that one table.  It seems to find the search term in the database regardless if it is typed in caps or not.  The triuble I have is being able to display thr results.  I want the search term to be displayed in bold in the results.  Example: searched for "time".  In the results, I want that term will be in bold, like "times".  That works fine as long as the text case is the same.  "Shoe will show up if it was all caps but it won't be in bold.  I was just wondering if there is a way that the search can show up in bold for example regardless of how the term is typed in?  Not sure if I made any sense here :P.

Link to comment
Share on other sites

Thanks effigy, but if I read that right str_ireplace ony works for PHP 5.  The place here is not running PHP 5.  They are running PHP 4?.  I think that is exactly what I was looking for, but since they arn't using PHP 5, is there another way I can around this?

Link to comment
Share on other sites

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.