function rearr($array) { arrayRecursive($array, 'urlencode', true); $data = new Data(); $data->setData($array); $data->setMd5(md5(urldecode(json_encode($array)))); $_SESSION['token'] = md5(time()); $data->setToken($_SESSION['token']); echo urldecode(json_encode($data)); }
function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { static $recursive_counter = 0; if (++$recursive_counter > 1000) { die('possible deep recursion attack'); } foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } $recursive_counter--; }
function getJsonString($array) { /************************************************************** * * 使用特定function对数组中所有元素做处理 * @param string &$array 要处理的字符串 * @param string $function 要执行的函数 * @return boolean $apply_to_keys_also 是否也应用到key上 * @access public * *************************************************************/ $arrayRecursive = function (&$array, $function, $apply_to_keys_also = true) { static $recursive_counter = 0; if (++$recursive_counter > 1000) { die('possible deep recursion attack'); } foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = is_string($value) ? $function($value) : $value; } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } $recursive_counter--; }; $arrayRecursive($array, 'urlencode', true); $json = json_encode($array); return urldecode($json); }
if (is_array($list[0][$thekey]) || gettype($list[0][$thekey]) == 'object') { arrayRecursive($list[0][$thekey], 'htmlspecialchars', true, $cs); echo "<pre>"; print_r($list[0][$thekey]); echo "</pre>"; } else { $unser = @unserialize($list[0][$thekey]); if (is_array($unser)) { arrayRecursive($unser, 'htmlspecialchars', true, $cs); echo "<pre>"; print_r($unser); echo "</pre>"; } else { if ($unser == false) { $jsonstr = json_decode($list[0][$thekey], true); if ($jsonstr == null) { echo "FormatFail"; } else { if (is_array($jsonstr)) { arrayRecursive($jsonstr, 'htmlspecialchars', true, $cs); echo "<pre>"; print_r($jsonstr); echo "</pre>"; } else { echo "FormatFail"; } } } } } }
function JSON($array) { arrayRecursive($array, 'urlencode', true); $json = json_encode($array); return urldecode($json); }
/** * return json string * * @return string */ function array2json($array, $cs) { arrayRecursive($array, 'urlencode', true, $cs); return json_encode($array); }
private function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } }
function showJson($array) { arrayRecursive($array, 'urlencode', TRUE); $json = json_encode($array); return urldecode($json); }
/** * * @将数组统一进行urlencode(兼容中文) * @$array 要转换的数组 * @return array 转换后的数组 * */ function cn_url_encode($array) { arrayRecursive($array, "urlencode", true); return $array; }
function json_output() { global $_json_result; arrayRecursive($_json_result, 'urlencode', false); print urldecode(json_encode($_json_result)); }
function operation_fail($message, $error = ERR_GAME_OPERATION_FAIL) { print urldecode(json_encode(array("error" => arrayRecursive($error, 'urlencode'), "message" => arrayRecursive($message, 'urlencode')))); exit; }