Created
September 11, 2014 15:38
-
-
Save khoand0000/5f94cd40bb9d0a888931 to your computer and use it in GitHub Desktop.
http://phpsnips.com/603/Escape-user-input-before-preg_replace#.VBG_A_mSySo
Sometimes you need to do preg_replace on user input. Don't forget to escape all special characters or you'll get funny results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = str_replace(array('^', '.', '|', '(', ')', '[', ']', '*', '+', '?', '{', '}', '$' ), | |
array('\^', '\.', '\|', '\(', '\)', '\[', '\]', '\*', '\+', '\?', '\{', '\}', '\$' ), $input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment