A customer reported a bug and I've traced it to this code, but I can't figure out what is wrong with it:
$source = "This is a test.\n\n-- a <span style='color:red'>red word</span>!\n\n- a red word!\n\n";
//$find = "- a red word!"; // This one works!
$find = "- a <span style='color:red'>red word</span>!"; // This one doesn't...
$replace = "• a <span style='color:red'>red word</span>!";
$pattern = '/^' . preg_quote($find) . '$/';
$results = preg_replace($pattern, $replace, $source);
die ("Results: " . serialize($results));
I've included a sample of a $find
that works vs a $find
that doesn't work. Any idea why the uncommented $find
doesn't work?
(Note: I'm not actually trying to parse HTML and the search is purely a sample, so I don't need corrections on the approach)