note 49994 added to function.stripslashes
| From: | ferik100 at flexis dot com dot br | Date: | Tue, 15 Feb 2005 00:05:01 +0000 |
| Subject: | note 49994 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85035@lists.php.net to get a copy of this message | ||
Here's a function to get rid of slashes added by magic_quotes_gpc. The parameter it takes can
be either a string or an array. I use it to clean up $_POST arrays before processing their contents
(rather than stripping slashes from each key and value as the contents are being processed).
function strip_gpc_slashes ($input)
{
if ( !get_magic_quotes_gpc() || ( !is_string($input) && !is_array($input) ) )
{
return $input;
}
if ( is_string($input) )
{
$output = stripslashes($input);
}
elseif ( is_array($input) )
{
$output = array();
foreach ($input as $key => $val)
{
$new_key = stripslashes($key);
$new_val = strip_gpc_slashes($val);
$output[$new_key] = $new_val;
}
}
return $output;
}
Note: With PHP5 at least this function will preserve user-submitted slashes, so if a user types
'test\' in a form field, this function will return exactly 'test\', not
'test', as suggested by mattyblah at gmail dot com.
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49994
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49994&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49994&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49994&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49994&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49994&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49994&report=yes
Search -- http://master.php.net/manage/user-notes.php