I am trying to replace some text if it isn't preceded with a dot (.), but my function seems to result include an unexpected slash ...
<?php
$test="function insertXYZ(e){e.insertXYZ()};";
$search="insertXYZ(";
$replace="zzzz(";
$search=str_replace("(", '\(', $search);
//echo $search."\n\n";
$pattern = '\b' . $search;
$replaceException="999";
$test=preg_replace('/' . "\.".$pattern . '/', "$replaceException", $test);
$test=preg_replace('/' . $pattern . '/', $replace, $test);
$test=preg_replace('/' . $replaceException . '/', ".$search", $test);
echo $test;
?>
A sample of this code can be found at http://sandbox.onlinephpfunctions.com/code/24cab4eece20d22a11dd887da44d63e393b51aa9
which outputs...
function zzzz(e){e.insertXYZ\()};
^
but I want the output to read...
function zzzz(e){e.insertXYZ()};
^
Where am I going wrong?