简体   繁体   中英

php - filter_var() expects 3 arguments max

I'm using filter_var() over my strings to sanitize them.

return filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP);

filter_var() takes at most 3 arguments, but it gives so many options and I WANT ALL OF THEM!!!

How do I do this properly? The examples here: http://php.net/manual/en/filter.filters.sanitize.php don't seem to use more than one at a time.

Surely someone must have wanted to strip both ASCII<32 and ASCII>127 without calling filter_var() twice at some point, right? Is it as simple as doing FILTER_FLAG_STRIP_LOW & FILTER_FLAG_STRIP_HIGH? Or maybe using a bitwise or?

They're bit flags - if you want to use multiple flags, you have to bitwise-OR them into a single value:

filter_vars($str, FILTER_SANITIZE_STRING, flag1 | flag2 | .... | flagN)
                                                ^-------^---etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM