/** * A wrapper for json_encode function * We need to pass valid UTF-8 string to json_encode, otherwise it may return NULL * * @param mixed * @return string */ function evo_json_encode($a = false) { if (is_string($a)) { // Convert to UTF-8 $a = current_charset_to_utf8($a); } elseif (is_array($a)) { // Recursively convert to UTF-8 array_walk_recursive($a, 'current_charset_to_utf8'); } return json_encode($a); }
/** * A wrapper for json_encode function * We need to pass valid UTF-8 string to json_encode, otherwise it may return NULL * * @param mixed * @return string */ function evo_json_encode($a = false) { if (is_string($a)) { // Convert to UTF-8 $a = current_charset_to_utf8($a); } elseif (is_array($a)) { // Recursively convert to UTF-8 array_walk_recursive($a, 'current_charset_to_utf8'); } $result = json_encode($a); if ($result === false) { // If json_encode returns FALSE because of some error we should set correct json empty value as '[]' instead of false $result = '[]'; } return $result; }