$remarks = preg_replace('/'.$searchText.'/i', '<span class="searchText">$0</span>', $remarks);
I use the line of code above to highlight the search text that has been entered by the user. It works 99% of the time except when the search string happens to contain a forward slash (/) character. When they do that, php returns a "unknown modifier" error. I've tried escaping the forward slash with a back slash character by adding this line of code ahead of the preg_replace line.
$searchText = str_replace('/', '\/', $searchText);
That doesn't seem to help. How do I make this work?
str_replaceinstead ofpreg_replacein your additional line to remove any additional slashes? With the additional line also, have you tried replacing the / with nothing rather than escaping it?