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 Link to comment https://forums.phpfreaks.com/topic/164372-foreach-on-_post-or-_get/ 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); } } Link to comment https://forums.phpfreaks.com/topic/164372-foreach-on-_post-or-_get/#findComment-867142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.