PHP Super filter function
PHP Super filter function
Do you always go through the previous filtering code every time you want to filter?
Have you searched for PHP solutions to prevent filtering and attack?
Do you fully follow the 'filter inputs and avoid output' standard in the Web field?
In fact, these problems require frequent filtering out of input data. Therefore, based on the experience of writing so many codes, it is more reliable to filter the whitelist!
Of course, if you have any better code or something, please leave a message to discuss it!
I found that I have been writing some filtering problems recently, and I have been writing PHP for a year or two. I found that the filtering problem has always been a big problem, the following shows a general whitelist-based filter function,
If you cannot use it, contact my qq852208555 for further discussion!
Implementation of GBK GB2312 encoding
Below is the UTF-8 pattern :( mainly Chinese character match different)
AlFilter ($ str = NULL, $ operate, $ ext = NULL) {if (! $ Str) return 0; // matching mode $ pattern $ Cp = "\ x {4e00}-\ x {9fff}"; $ Dp = '0-9 '; $ Wp = 'A-zA-Z'; $ Tp = '#% % ^ & * ()-+ ='; $ _ p = '_'; $ pattern = "/^ ["; $ OArr = str_split (strtolower ($ operate); // The split operator if (in_array ('C', $ OArr) $ pattern. = $ Cp; if (in_array ('D', $ OArr) $ pattern. = $ Dp; if (in_array ('W', $ OArr) $ pattern. = $ Wp; if (in_array ('t', $ OArr) $ pattern. = $ Tp; if (in_array ('_', $ OArr) $ pattern. = $ _ p; if ($ ext) $ pattern. = $ ext; $ pattern. = "] + $/U "; if (! Preg_match ($ pattern, $ str) return 0; else return $ str ;}
Of course, you can only use the UTF-8 GBK transcoding in the past to match... and vice versa, but I think the trouble of course there is a better way to improve, welcome to discuss, don't hesitate to enlighten me!
Reposted from happy love my blog address: http://blog.csdn.net/lovehappying this article address