If you’re going to use replacement text that has ‘$’ or ” in it, chances are it is going to be treated as a backreference. Any parentheses you include in your regex will be captured and placed into the replacement text. If you don’t want this, you need to escape the ‘$’ as ‘$’ and the ” as ‘'. One example is if you wanted to replace ‘COST’ with ‘$12345’. The preg_replace_escape_back() function will sort this out: