sql错误:SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x8D\x83' for column 'user_nickname' at row 1
网上找的解决方法
public function demo()
{
$str = "□测试,测试!123□";
//转换 GB2312 -> UTF-8
$str = mb_convert_encoding($str, 'UTF-8', 'GB2312');
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);
$str = join('', $matches[0]);
//转换 UTF-8 -> GB2312
$str = mb_convert_encoding($str, 'GB2312', 'UTF-8');
dump($str);
$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
echo $str; //输出 中文字符
}
输出乱码:
添加:header('Content-Type:text/html; charset=utf-8');
依旧是乱码;
转码失败 我只能进行字符删除了
{
$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
echo $str; //输出 中文字符
}