编辑代码

<?php
$array = [
    'name' => '张三',
    'age' => 30,
    'city' => '北京'
];

$json = json_encode($array, JSON_UNESCAPED_UNICODE);

echo $json;

die;

$str = "<h1>Hello WorldÆØÅÆØÅÆØÅÆØÅ!</h1>";

$newstr = filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
echo $newstr;
die;
// 用户定义的异常处理函数
 function myException($exception) {
     echo "<b>Exception:</b> ", $exception->getMessage();
 }

 // 设置用户定义的异常处理函数
 set_exception_handler("myException");

// 抛出异常
throw new Exception("Uncaught exception occurred!");

die;
class customException
{
    public function errorMessage()
    {
        // // 错误信息
        // $errorMsg = '错误行号 '.$this->getLine().' in '.$this->getFile()
        // .': <b>'.$this->getMessage().'</b> 不是一个合法的 E-Mail 地址';
        // return $errorMsg;
        return 'aaaaa';
    }
}
 
$email = "someone@example...com";
 
try
{
    // 检测邮箱
    if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
    {
        // 如果是个不合法的邮箱地址,抛出异常
        throw new customException($email);
    }
}
 
catch (customException $e)
{
//display custom message
echo $e->errorMessage();
}
?>