Last Updated: February 25, 2016
·
592
· brandon-kp

Prevent accidental back-references

$conf['content'] = "Buy this thing for $300";

You can't ask the user building their configs to escape the dollar sign, and you can't just leave it as-is, otherwise you'll end up with something like "Buy this thing for 0". So before you do your preg_replace'ing, do this:

$content = preg_replace(
    '/\\$\\d+/', 
    '\\\\$0', 
    $conf['content']
);