0

In the system I am developing I have implemented a function that highlights the searched word (word that is passed in a query) here's the function

function bold_word( $content, $word) {
    $replace = '<span class="font-weight-bold">' . $word . '</span>'; // create replacement
    $content = str_replace( $word, $replace, $content ); // replace content
    return $content; // return highlighted data
}

the problem is that the word being searched for must be identical. if the one entered in the database has a capital letter (such as a surname or a name) the word is not highlighted if the name "Tommy" is entered in the database and the employee searches for tommy, the parlor is not highlighted. how can i solve?

Ihor Vyspiansky
  • 918
  • 1
  • 6
  • 11
  • see this for a case insensitive search: https://stackoverflow.com/questions/27339034/make-search-in-text-file-case-insensitive – Luuk Aug 18 '20 at 17:20
  • Did you try `str_ireplace` - case-insensitive version of `str_replace()`? https://www.php.net/manual/en/function.str-ireplace.php – Ihor Vyspiansky Aug 18 '20 at 17:24

0 Answers0