note 90788 added to function.stripslashes
| From: | shredder at technodrome dot com | Date: | Sat, 09 May 2009 22:50:42 +0000 |
| Subject: | note 90788 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154402@lists.php.net to get a copy of this message | ||
Hi,
Here are recursive addslashes / stripslashes functions.
given a string - it will simply add / strip slashes
given an array - it will recursively add / strip slashes from the array and all of it subarrays.
if the value is not a string or array - it will remain unmodified!
<?php
function add_slashes_recursive( $variable )
{
if ( is_string( $variable ) )
return addslashes( $variable ) ;
elseif ( is_array( $variable ) )
foreach( $variable as $i => $value )
$variable[ $i ] = add_slashes_recursive( $value ) ;
return $variable ;
}
function strip_slashes_recursive( $variable )
{
if ( is_string( $variable ) )
return stripslashes( $variable ) ;
if ( is_array( $variable ) )
foreach( $variable as $i => $value )
$variable[ $i ] = strip_slashes_recursive( $value ) ;
return $variable ;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 152.62.109.164
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- https://master.php.net/note/edit/90788
Del: integrated -- https://master.php.net/note/delete/90788/integrated
Del: useless -- https://master.php.net/note/delete/90788/useless
Del: bad code -- https://master.php.net/note/delete/90788/bad+code
Del: spam -- https://master.php.net/note/delete/90788/spam
Del: non-english -- https://master.php.net/note/delete/90788/non-english
Del: in docs -- https://master.php.net/note/delete/90788/in+docs
Del: other reasons-- https://master.php.net/note/delete/90788
Reject -- https://master.php.net/note/reject/90788
Search -- https://master.php.net/manage/user-notes.php