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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:51:04+00:00 2026-05-17T22:51:04+00:00

In the function below, I want to match the keyword case insensitive (should match

  • 0

In the function below, I want to match the keyword case insensitive (should match “Blue Yoga Mats” and “blue yoga mats”)…

However, it currently only matches if the keyword is the same case.

$mykeyword = “Blue Yoga Mats”;

$post->post_content = preg_replace_callback("/\b($mykeyword)\b/","doReplace", $post->post_content);

// the callback function
function doReplace($matches)
{
    static $count = 0;

    // switch on $count and later increment $count.
    switch($count++) {
        case 0: return '<b>'.$matches[1].'</b>';   // 1st instance, wrap in bold
        case 1: return '<em>'.$matches[1].'</em>'; // 2nd instance, wrap in italics
        case 2: return '<u>'.$matches[1].'</u>'; // 3rd instance, wrap in underline
        default: return $matches[1];              // don't change others.
            }
    }
  • 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-17T22:51:05+00:00Added an answer on May 17, 2026 at 10:51 pm

    Simply add the i modifier to your regex to make it perform a case insensitive match:

    "/\b($mykeyword)\b/i"
    

    By the way, if you haven’t already, you need to escape special regex characters from your keyword. In case any are present, they could screw up your regex and cause PHP warnings/errors. Call preg_quote() before you perform the replacement:

    $mykeyword_escaped = preg_quote($mykeyword, '/');
    $post->post_content = preg_replace_callback("/\b($mykeyword_escaped)\b/i","doReplace", $post->post_content);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at the function below. I want to pass a vector of factors and
i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
In the function below chld is null only in IE, in firefox the javascript
I have a table (AreaPartners), and I want to match only the first Name
Lets say we've got a function like f below, that returns a monad. However,
I have problem mixing pattern match and curdate() function. Below is the table structure,
I have two jQuery functions. The first one below I want to run first,
My function below, will take the values from my custom meta fields (after a
My function below calls a partial view after a user enters a filter-by string
I have the function below. It gets the values from checked boxes and transfer

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.