]> git.mjollnir.org Git - moodle.git/commitdiff
added recursive addslashes
authorskodak <skodak>
Fri, 16 Feb 2007 09:38:24 +0000 (09:38 +0000)
committerskodak <skodak>
Fri, 16 Feb 2007 09:38:24 +0000 (09:38 +0000)
lib/weblib.php

index d5d330084ce28aee1abebde1dce73fd1695bb72c..f35afdace63d5f41267895cb2d18db95d0a48b03 100644 (file)
@@ -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