allinurl Posted April 1, 2008 Share Posted April 1, 2008 Hello. Im sanitizing an array of $_POST values with the function sanitize_values(), what Im trying to do now is to sanitize the array but instead of doing the way Im doing it I would like to do it using strip_tags and htmlentities. What could be the best way of doing this using those functions mentioned before. Thanks in advance function sanitize_values($value) { $search = array( '&', '\\', '<', '>', '[', ']' ); $replace = array( '&', '\', '<', '>', '[', ']' ); $str = str_replace( $search, $replace, $str ); return( $str ); } Quote Link to comment Share on other sites More sharing options...
zq29 Posted April 1, 2008 Share Posted April 1, 2008 return htmlentities(strip_tags($str),ENT_QUOTES); Quote Link to comment Share on other sites More sharing options...
allinurl Posted April 1, 2008 Author Share Posted April 1, 2008 Thanks for your reply, the problem is that Im not passing it as a string, Im passing it as an array. Quote Link to comment Share on other sites More sharing options...
papaface Posted April 1, 2008 Share Posted April 1, 2008 function sanitize_values($array) { foreach ($array as $k => $v) { $array[$k] = htmlentities(strip_tags($v),ENT_QUOTES); } return $array; } or: function sanitize_values($val) { if (is_array($val)) { foreach ($val as $k => $v) { $val[$k] = htmlentities(strip_tags($v),ENT_QUOTES); } } else { $val = htmlentities(strip_tags($val),ENT_QUOTES); } return $val; } Quote Link to comment Share on other sites More sharing options...
zq29 Posted April 1, 2008 Share Posted April 1, 2008 Alternatively... <?php function clean($var) { if(is_array($var)) { array_map("clean",$var); } else { $var = htmlentities(strip_tags($var),ENT_QUOTES); } return $var; } ?> Quote Link to comment Share on other sites More sharing options...
allinurl Posted April 1, 2008 Author Share Posted April 1, 2008 Thanks alot, that's what I was looking for... Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 solve topic please 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.