Return to Snippet

Revision: 33423
at October 8, 2010 17:18 by iusik


Initial Code
function json_safe_encode($var)
{
   return json_encode(json_fix_cyr($var));
}

function json_fix_cyr($var)
{
   if (is_array($var)) {
       $new = array();
       foreach ($var as $k => $v) {
           $new[json_fix_cyr($k)] = json_fix_cyr($v);
       }
       $var = $new;
   } elseif (is_object($var)) {
       $vars = get_object_vars($var);
       foreach ($vars as $m => $v) {
           $var->$m = json_fix_cyr($v);
       }
   } elseif (is_string($var)) {
       $var = iconv('cp1251', 'utf-8', $var);
   }
   return $var;
}

//Some array with Cyrillic letters $cyrillic_word.


json_safe_encode($cyrillic_word);

Initial URL

                                

Initial Description

                                

Initial Title
json_encode for Cyrillic Language

Initial Tags

                                

Initial Language
PHP