From 04480de3860fc7203ce902f76c49f62689cbab5c Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 16 Feb 2007 09:38:24 +0000 Subject: [PATCH] added recursive addslashes --- lib/weblib.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/weblib.php b/lib/weblib.php index d5d330084c..f35afdace6 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -366,6 +366,35 @@ function stripslashes_recursive($var) { return $var; } +/** + * Recursive implementation of addslashes() + * + * This function will allow you to add the slashes from a variable. + * If the variable is an array or object, slashes will be added + * to the items (or properties) it contains, even if they are arrays + * or objects themselves. + * + * @param mixed the variable to add slashes from + * @return mixed + */ +function addslashes_recursive($var) { + if(is_object($var)) { + $properties = get_object_vars($var); + foreach($properties as $property => $value) { + $var->$property = addslashes_recursive($value); + } + } + else if(is_array($var)) { + foreach($var as $property => $value) { + $var[$property] = addslashes_recursive($value); + } + } + else if(is_string($var)) { + $var = addslashes($var); + } + return $var; +} + /** * Given some normal text this function will break up any * long words to a given size by inserting the given character -- 2.39.5