Avatar of willsherwood
willsherwood

asked on 

PHP regex how to replace with the same string

the following statement works:

$display_html =
preg_replace(
   "/".$search_string."/i",
   "<b class='highlight'>".$search_string."</b>",
    $row['title'] );

where search_string is what is being searched for, and 'title'
is the  LIKE-matching result from a mysql database.

currently the regex substitutes the CASE that was used as typed in by the searcher.
I would like to have the CASE retained to that of what the field was in the database
(could be lower, initial cap, all caps, etc.)

how can the regex substitution (which surrounds the title search phrase with HTML tags for highlighting)
be altered to retain the the capitalization in the returned field result.
PHP

Avatar of undefined
Last Comment
willsherwood

8/22/2022 - Mon