magicmoose Posted July 1, 2009 Share Posted July 1, 2009 Hi, I'm trying to filter all input on my site but I'm having some trouble with the syntax. I tried to use this.. foreach($_POST as $key => $val) { $_POST[$key] = htmlentities($_POST[$key]); } foreach($_GET as $key => $val) { $_GET[$key] = htmlentities($_GET[$key]); } But get the error Warning: htmlentities() expects parameter 1 to be string, array given Can anyone give me any advice on how to do this? Thanks Quote Link to comment Share on other sites More sharing options...
flyhoney Posted July 1, 2009 Share Posted July 1, 2009 This is untested, but it is how I would probably tackle the problem. I created a recursive htmlentities function that will accept arrays of strings. <?php $globals = array($_POST, $_GET); foreach ($globals as &$global) { foreach ($global as $key => $val) { $global[$key] = rhtmlentities($val); } } function rhtmlentities($mixed) { if (is_array($mixed)) { foreach ($mixed as $key => $value) { $mixed[$key] = rhtmlentities($value); } } else if (is_string($mixed)) { return htmlentities($mixed); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.