//返回json数据给js function json_output($err_code = 0 , $error_message = '' , $data = [] , $redirect = '',$jsonp = FALSE){ $ret = array( 'error_code' => $err_code, 'error_message' => $error_message, 'data' => is_array($data)?$data:(array)$data, 'redirect' => $redirect, ); header("Content-Type:application/json;charset=utf-8"); $output = json_encode($ret); if($jsonp){ $callback_func = isset($_GET['callback'])?$_GET['callback']:md5(time()); $output = $callback_func.'('.$output.')'; } echo $output;exit; } /** * 计算中文字符串长度 */ function utf8_strlen($string = null) { // 将字符串分解为单元 preg_match_all ( '/./us', $string, $match ); // 返回单元个数 return count ( $match [0] ); }