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 ); } Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/ Share on other sites More sharing options...
zq29 Posted April 1, 2008 Share Posted April 1, 2008 return htmlentities(strip_tags($str),ENT_QUOTES); Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506778 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. Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506792 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; } Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506794 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; } ?> Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506812 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... Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506821 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 solve topic please Link to comment https://forums.phpfreaks.com/topic/99040-solved-sanitizing-array-using-strip_tags-and-htmlentities/#findComment-506860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.