Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:43:10+00:00 2026-05-15T13:43:10+00:00

Possible Duplicate: highlighting search results in php/mysql I am doing a search with a

  • 0

Possible Duplicate:
highlighting search results in php/mysql

I am doing a search with a query, in MSSQL, like this:

SELECT ctext FROM Table WHERE ctext like '%filter%'

Then, I am wanting to highlight the hits with php:

 function highlightme($str, $filter){
     $html = "<FONT style=".chr(34)."BACKGROUND-COLOR: yellow".
     chr(34).">".$filter."</FONT></P>";
     $buf = str_replace($filter,$html,$str);
     return $buf;
 }

But, if the filter was ‘Hello’, and ctext contains ‘hello’, the SQL brings it, but php does not highlight it (I think it has to do with case sensitive)
And, If the filter was, ‘hellos’ and ctext contains ‘hello’, the SQL brings it, but php does not hightlight it either.

How can I solve this two things??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:43:11+00:00Added an answer on May 15, 2026 at 1:43 pm

    First of all, instead of using chr(34) you should use "\"" or '"'. I suggest that instead of using str_replace you use preg_replace, which allows you to specify a regexp pattern. You can use the i modifier to make the pattern case-insensitive.

    Example:

    CSS

    .keyword {
        color: yellow;
    }
    

    PHP

    $pattern = '#(hello)#i';
    $replacement = '<span class="keyword">\1</span>';
    $result = preg_replace($pattern, $replacement, $input);
    

    It is also possible to specify pattern and replacement as arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: zebra stripes over riding my highlighting color I am using this code
Possible Duplicate: How to disable highlighting of the app icon? Hi this is an
Possible Duplicate: Best way to stop SQL Injection in PHP I would like to
Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
Possible Duplicate: Fix for Xcode's indiscernible highlighting of inline errors? Does anyone know how
Possible Duplicate: How to: URL re-writing in PHP? How can a website use an
Possible Duplicate: How to minify php page html output? Any reason not to strip
Possible Duplicate: Best way to stop SQL Injection in PHP If I were to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.