Added Horde_Util::convertToUtf8().
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Mar 2010 18:37:17 +0000 (11:37 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Mar 2010 19:21:35 +0000 (12:21 -0700)
framework/Util/lib/Horde/Util.php
framework/Util/package.xml

index 6b07d54..b8ab56d 100644 (file)
@@ -905,4 +905,30 @@ class Horde_Util
         return base64_decode($data);
     }
 
+    /**
+     * Convert a variable to UTF-8. Recursively handles inner variables.
+     *
+     * @param mixed $in  The variable to convert.
+     *
+     * @return mixed  The converted variable.
+     */
+    static public function convertToUtf8($in)
+    {
+        if (is_string($in)) {
+            $in = utf8_encode($in);
+        } elseif (is_array($in)) {
+            reset($in);
+            while (list($key, $val) = each($in)) {
+                $in[$key] = self::convertToUtf8($in[$key]);
+            }
+        } elseif (is_object($in)) {
+            $in = self::cloneObject($in);
+            foreach (get_object_vars($in) as $key => $val) {
+                $in->$key = self::convertToUtf8($in->$key);
+            }
+        }
+
+        return $in;
+    }
+
 }
index 8afed38..f2b11b6 100644 (file)
@@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added Horde_Util::abbreviate().
+ <notes>* Added Horde_Util::convertToUtf8().
+ * Added Horde_Util::abbreviate().
  * Removed Horde_Array::combine() and Horde_Util::hmac().
  * Initial Horde 4 package.
  </notes>