Wednesday, 3 June 2015

escape user input before preg_replace

Sometimes you need to do preg_replace on user input. Don't forget to escape all special characters or you'll get funny results.

<?php 
$input 
str_replace(array('^''.''|''('')''['']''*''+''?''{''}''$' ),  
        array(
'\^''\.''\|''\(''\)''\[''\]''\*''\+''\?''\{''\}''\$' ), $input);

0 comments:

Post a Comment