note 26313 deleted from function.strip-tags by vrana
| From: | vrana@php.net | Date: | Mon, 22 Dec 2003 16:18:56 +0000 |
| Subject: | note 26313 deleted from function.strip-tags by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62331@lists.php.net to get a copy of this message | ||
Note Submitter: jsheets@shadonet.com
----
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.