Last Updated: February 25, 2016
·
953
· 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']
);

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside