本文整理汇总了PHP中core::json_encode方法的典型用法代码示例。如果您正苦于以下问题:PHP core::json_encode方法的具体用法?PHP core::json_encode怎么用?PHP core::json_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core
的用法示例。
在下文中一共展示了core::json_encode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: message
public function message($msg, $jumpurl = '')
{
if (core::gpc('ajax')) {
$arr = array('servererror' => '', 'status' => 1, 'message' => $msg);
echo core::json_encode($arr);
exit;
} else {
echo $msg;
exit;
}
}
示例2: display
public function display($file, $json = array())
{
if (!core::gpc('ajax', 'R')) {
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
// json 格式,约定为格式。
} else {
ob_start();
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
$body = ob_get_contents();
ob_end_clean();
$json = array('servererror' => '', 'status' => 1, 'message' => array('width' => 400, 'height' => 300, 'pos' => 'center', 'title' => '默认窗口标题', 'body' => ''));
$json['message'] = array_merge($json['message'], $this->json);
$this->fetch_json_header($body, $json['message']);
$json['message']['body'] = $body;
echo core::json_encode($json);
}
}
示例3: to_json
public static function to_json($e)
{
if (DEBUG) {
$arr = self::format_exception($e);
$backinfo = '';
foreach ($arr['backtracelist'] as $v) {
$backinfo .= "{$v['file']} [{$v['line']}] : {$v['class']}{$v['type']}{$v['function']}({$v['args']})\r\n";
}
$s = "{$arr['message']}\r\n File: {$arr['file']} [{$arr['line']}] \r\n \r\n {$backinfo}";
$s = str_replace(array(' ', '<br />', '>', '<'), array(' ', "\r\n", '>', '<'), $s);
$s = preg_replace('#[\\r\\n]+#', "\n", $s);
} else {
$s = $e->getMessage();
}
$s = preg_replace('# \\S*[/\\\\](.+?\\.php)#', ' \\1', $s);
//$s = preg_replace('#[\\x80-\\xff]{2}#', '?', $s);// 替换掉 gbk, 否则 json_encode 会报错!
$arr = array('servererror' => $s);
return core::json_encode($arr);
}
示例4: exception_handle
public static function exception_handle($e)
{
// 避免死循环
DEBUG && ($_SERVER['exception'] = 1);
core::ob_clean();
log::write($e->getMessage() . ' File: ' . $e->getFile() . ' [' . $e->getLine() . ']');
$s = '';
if (DEBUG) {
try {
if (self::gpc('ajax', 'R')) {
$s = xn_exception::to_json($e);
} else {
//!core::is_cmd() && header('Content-Type: text/html; charset=UTF-8');
$s = xn_exception::to_html($e);
}
} catch (Exception $e) {
$s = get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine();
}
} else {
if (self::gpc('ajax', 'R')) {
$s = core::json_encode(array('servererror' => $e->getMessage()));
} else {
$s = $e->getMessage();
}
}
echo $s;
exit;
}
示例5: error_handler
/**
* Custom error handler.
*
* Catches all errors (not exceptions) and creates an ErrorException.
* ErrorException then can caught by Yaf\ErrorController.
*
* @param integer $errno the error number.
* @param string $errstr the error message.
* @param string $errfile the file where error occured.
* @param integer $errline the line of the file where error occured.
*
* @throws ErrorException
*/
static function error_handler($errno, $errstr, $errfile, $errline)
{
// 防止死循环
$errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice');
$errnostr = isset($errortype[$errno]) ? $errortype[$errno] : 'Unknonw';
// 运行时致命错误,直接退出。并且 debug_backtrace()
$s = "[{$errnostr}] : {$errstr} in File {$errfile}, Line: {$errline}";
// 抛出异常,记录到日志
//echo $errstr;
if (DEBUG && empty($_SERVER['exception'])) {
throw new Exception($s);
} else {
log::write($s . date('Y-M-D H:i:s', $_SERVER['time']));
//$s = preg_replace('# \S*[/\\\\](.+?\.php)#', ' \\1', $s);
if (core::gpc('ajax', 'R')) {
core::ob_clean();
//$s = preg_replace('#[\\x80-\\xff]{2}#', '?', $s);// 替换掉 gbk, 否则 json_encode 会报错!
// 判断错误级别,决定是否退出。
if ($errno != E_NOTICE && $errno != E_USER_ERROR && $errno != E_USER_NOTICE && $errno != E_USER_WARNING) {
$s = core::json_encode(array('servererror' => $s));
throw new Exception($s);
exit;
} else {
$_SERVER['notice_error'] .= $s;
// 继续执行。
}
} else {
//echo $s;
// 继续执行。
}
}
return 0;
}
示例6: update
public function update($key, $data)
{
return $this->saekv->set($key, core::json_encode($data));
}