/** * Transform encoding * * @param $arr * @param $to * @param $from * * @return array */ private function transEncoding($arr, $to, $from) { $ret = array(); foreach ($arr as $key => $value) { if (is_array($value)) { $value = $this->transEncoding($value, $to, $from); } else { $value = Encoding::convert($value, $to, $from); } if (is_string($key)) { $key = Encoding::convert($key, $to, $from); } $ret[$key] = $value; } return $ret; }
/** * Transform encoding * * @param Application $app */ private function transEncoding(Application $app) { $ie = $app->request->inputEncoding; $to = $app->encoding; if ($ie === $to) { return; } // url上可能也有汉字啥的 $app->request->url = Encoding::convert($app->request->url, $to, $ie); $app->request->uri = Encoding::convert($app->request->uri, $to, $ie); Encoding::convertArray($app->request->inputs, $to, $ie); // 经过转码后把转码过的数据写会,$_GET/$_POST也可能被访问 foreach ($_GET as $key => $value) { if (isset($app->request->inputs[$key])) { $_GET[$key] = $app->request->inputs[$key]; } } foreach ($_POST as $key => $value) { if (isset($app->request->inputs[$key])) { $_POST[$key] = $app->request->inputs[$key]; } } }