Update replace() to correctly apply preg_quote to pattern and replacement