Scooby08 Posted November 15, 2011 Share Posted November 15, 2011 Here's an example of my issue with the dollar sign.. This one treats the dollar sign like an expression.. <?php $input = '<div>stuff</div>'; $replace = '<div>$600,000. Test? Test!</div>'; $output = preg_replace('/<div>(.*?)<\/div>/',$replace,$input); echo $output; // <div>0,000. Test? Test!</div> ?> So I tried out preg_quote and now the dollar sign is fixed, but the punctuation now has slashes which are not wanted.. <?php $input = '<div>stuff</div>'; $replace = '<div>'.preg_quote('$600,000. Test? Test!').'</div>'; $output = preg_replace('/<div>(.*?)<\/div>/',$replace,$input); echo $output; // <div>$600,000\. Test\? Test\!</div> ?> I guess I'm looking for the best alternative to this situation so that dollar signs aren't treated like expressions and the punctuation does not have backslashes.. Thanks! Link to comment https://forums.phpfreaks.com/topic/251201-preg_replace-issue-when-replace-content-has-a-dollar-sign/ Share on other sites More sharing options...
freelance84 Posted November 15, 2011 Share Posted November 15, 2011 $ is a special symbol so needs to be negated, http://www.regular-expressions.info/characters.html this site is pretty awesome Link to comment https://forums.phpfreaks.com/topic/251201-preg_replace-issue-when-replace-content-has-a-dollar-sign/#findComment-1288401 Share on other sites More sharing options...
xyph Posted November 15, 2011 Share Posted November 15, 2011 This is generally known as escaping a character Link to comment https://forums.phpfreaks.com/topic/251201-preg_replace-issue-when-replace-content-has-a-dollar-sign/#findComment-1288491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.