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 8593433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:59:16+00:00 2026-06-11T23:59:16+00:00

I have a search feature which is coded below and i was wondering whether

  • 0

I have a search feature which is coded below and i was wondering whether it is possible to keep the original formatting. for example if i have the following piece of text, “Hello, I’m new to PHP” and in my search box i type “php” in lower case, in the results it will change the original upper case ‘PHP’ to a lower case ‘php’. is it possible to leave the string at its original state of PHP whether the user searches PhP or pHp etc.

here is the function containing the ‘str_ireplace’…

function boldText($text, $kword) {
    return preg_replace('/($kword)/i', "<strong><font color='Red'>$kword</font></strong>", $text);

and here is where it is called…

 echo "<td width = 130px><b>".boldText($info['company_name'], $kword) . "</b></td> ";
 echo "<td width = 60px>".boldText($info['section_name'], $kword) . " </td>"; 
 echo "<td width = 300px>".boldText($info['question'], $kword) . " </td>";
 echo "<td width = 600px>".boldText($info['answer'], $kword) . " </td></tr>"; 

Thanks

  • 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-06-11T23:59:17+00:00Added an answer on June 11, 2026 at 11:59 pm

    Use regular expressions. The modifier i stands for case insensitive

    echo preg_replace('/(php)/i', "<strong><font color='Red'>$1</font></strong>", 'I am new to pHp')
    // returns "I am new to <strong><font color='Red'>pHp</font></strong>"
    

    In context of your function:

    function boldText($text, $kword) {
        return preg_replace('/('.$kword.')/i', "<strong><font color='Red'>$1</font></strong>", $text);
    }
    

    Single quoted strings do not parse variables that are inside!

    So you need '/('.$kword.')/i' or "/($kword)/i".

    Inside dobule quoted strings variables are parsed, but always be aware of strange side effects, with weird combinations.

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

Sidebar

Related Questions

I have to implement a search feature which is able to quickly perform arbitrary
So I have this website that has a search feature which searches a table
I have a form which has a search feature - a single text field
In my website I have implemented search feature using full-text search. It works fine
I have created a search feature for a site and in addition I made
I have an app that includes a search feature. This feature is implemented by
I have been tasked with creating a site wide search feature. The search needs
I haven't implemented a search feature before and feel a bit stuck. I have
I'm using Youtube API, I'd like to have a search auto-complete feature, just like
I'm using jQuery. I have website feature that does an ajax search and returns

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.