function NP_UTF8_encode($obj) { if (gettype($obj) == "array") { foreach ($obj as $k => $v) { $obj[$k] = NP_UTF8_encode($v); } } else { if (gettype($obj) == "object") { foreach (get_object_vars($obj) as $k => $v) { $obj->{$k} = NP_UTF8_encode($v); } } } if (gettype($obj) == "string") { return utf8_encode($obj); } else { return $obj; } }
function NP_json_encode($obj) { if (gettype($obj) == "object") { if (version_compare(phpversion(), '5.0') < 0) { $obj = $obj; } else { $obj = clone $obj; } } if (function_exists("json_encode")) { return json_encode(NP_UTF8_encode($obj)); } else { require_once 'Zend/Json.php'; return Zend_Json::encode(NP_UTF8_encode($obj)); } }