note 49994 deleted from function.stripslashes by philip

From: Date: Wed, 07 Feb 2007 04:56:40 +0000
Subject: note 49994 deleted from function.stripslashes by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123015@lists.php.net to get a copy of this message
Note Submitter: ferik100 at flexis dot com dot br ---- 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.

« previous php.notes (#123015) next »