note 26313 added to function.strip-tags

From: Date: Fri, 25 Oct 2002 22:59:23 +0000
Subject: note 26313 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-38573@lists.php.net to get a copy of this message
Here is a function I use to cleanup data from the user, you should do additional checks i.e. make sure a variable is_numeric if you are expecting a numeric value but this does a pretty good job of removing a lot of the things a user will try to do. This function uses recursion so it will clean multi-dimensional arrays as well. function clean_array(&$array) { foreach ($array as $arraykey => $arrayvalue) { if (is_array($arrayvalue)) { clean_array($array[$arraykey]); } else { $array[$arraykey] = trim(stripslashes(strip_tags($arrayvalue))); } } } Here is an example: $uservars = $_REQUEST; clean_array($uservars); This example assigns $_REQUEST to $uservars and then cleans them, I've had problems assigning to $_REQUEST directly so I copy it into another variable. $_REQUEST can be multi-dimensional without a problem. -- http://www.php.net/manual/en/function.strip-tags.php http://master.php.net/manage/user-notes.php?action=edit+26313 http://master.php.net/manage/user-notes.php?action=delete+26313 http://master.php.net/manage/user-notes.php?action=reject+26313

« previous php.notes (#38573) next »