I'm running a preg_replace on content that I don't necessarily control and I'm running into an issue with replacement values containing things like currency values (i.e. $1.00
). Admittedly this is a common problem that's been addressed in other questions. The closest solution I've found is:
http://www.procata.com/blog/archives/2005/11/13/two-preg_replace-escaping-gotchas/
My problem is more complicated because the replacement value is not something I can escape ahead of time, at least not in a way I can see. Here's my preg code:
$body = preg_replace('/<special_tag id="'.$tagID.'">(.*?)<\/special_tag>/','$1',$body);
As you can see I'm capturing all content within a set custom tag, and removing the surrounding opening and closing tags, but keeping the content found inside. The replacement '$1'
however doesn't lend itself to the escaping that is required, and so currency values that happen to be in the replacement values are getting terminated incorrectly.
Have I over thought this replacement? Is there something else I can use to remove my special tags keeping in mind that it must take into account the unique ID for that specific tag?
Any help would be greatly appreciated!