I have the following piece of code which replaces "template markers" such as %POST_TITLE% with the contents of a variable called $post_title.
function replaceTags( $template, $newtext ) {
$template = preg_replace( '/%MYTAG%/', $newtext, $template );
return $template;
}
The issue is that when $post_full has a '$' in it, the returned result has this removed. For example:
$template = "Replace this: %MYTAG";
$newtext = "I earn $1,000,000 a year";
print replaceTags( $template, $newtext );
// RESULT
Replace this: I earn ,000,000 a year";
I know this has something to do with not properly escaping the $1 in the $newtext. I have tried using preg_quote() but it doesn't have the desired effect.