I have some flags I store in my mysql database so I can dynamically generate links and title tags using the following code; however, it seems to parse anything with a dollar sign as a variable.
foreach($result as $value){
$id = $value['id'];
$title = $value['title'];
$synopsis = $value['synopsis'];
$synopsis = preg_replace('/<!--TITLE-->/', $title, $synopsis);
}
So if the title is “$500,000 donated to blah blah” it will output “0,000 donated to blah blah”. How can I make it not parse this out? I’m not able to store the ascii value $ in the database for this particular case.
preg_replacelooks through the second string and if it sees a $, treats it and the digits that follow as a reference to the capture group with that number. (It only takes the first two digits, though; the number ranges from 0 to 99.) And since you don’t have a 50th capture group, it interprets the$50as nothing.If you’re just looking to find and replace a known string rather than a pattern, try using
str_replaceinstead ofpreg_replace. It doesn’t have such gotchas.