I've been working on my own templating feature in which a page of static html is replaced by php variables when they exist. When $ (dollar sign) exists on the static page before the templating magic it is getting omitted when i replace things using preg_replace() for the output.
This simple example illustrates this:
$price = '$10.99';
$template = 'Your cost: $price';
$output = preg_replace('/\$price/', $price, $template);
echo $output; //Your cost: .99
notice the "$" is now missing from output.
Anyone know how to solve this problem and preserve dollar signs in an elegant way.
I know I can do something like $price = str_replace('$', '\$', $price); but that seems ugly and simply another string function that isn't necessary. (I'm already using a lot of resources to make the templating feature work)
Note: I'm using php ver. 5.2
I thought maybe preg_replace_callback() might work but it doesn't seem to be supported