note 99183 added to function.stripslashes
| From: | jeremycook0 at googlemail dot com | Date: | Sun, 01 Aug 2010 15:04:24 +0000 |
| Subject: | note 99183 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171320@lists.php.net to get a copy of this message | ||
Here's a way of stripping slashes in PHP 5.3 using a recursive closure:
<?php
if (get_magic_quotes_gpc()) {
$strip_slashes_deep = function ($value) use (&$strip_slashes_deep) {
return is_array($value) ? array_map($strip_slashes_deep, $value) : stripslashes($value);
};
$_GET = array_map($strip_slashes_deep, $_GET);
$_POST = array_map($strip_slashes_deep, $_POST);
$_COOKIE = array_map($strip_slashes_deep, $_COOKIE);
}
?>
Note that the variable '$strip_slashes_deep' has to be passed to the closure by reference.
I think that this is because at the time the closure is created the variable
'$strip_slashes_deep' doesn't exist: the closure itself becomes the value of the
variable. Passing by reference solves this issue. This closure could easily be adapted to use other
methods of stripping slashes such as preg_replace().
----
Server IP: 66.207.199.35
Probable Submitter: 65.95.29.196
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- https://master.php.net/note/edit/99183
Del: integrated -- https://master.php.net/note/delete/99183/integrated
Del: useless -- https://master.php.net/note/delete/99183/useless
Del: bad code -- https://master.php.net/note/delete/99183/bad+code
Del: spam -- https://master.php.net/note/delete/99183/spam
Del: non-english -- https://master.php.net/note/delete/99183/non-english
Del: in docs -- https://master.php.net/note/delete/99183/in+docs
Del: other reasons-- https://master.php.net/note/delete/99183
Reject -- https://master.php.net/note/reject/99183
Search -- https://master.php.net/manage/user-notes.php