mysql 口字符号怎么处理?

WBOY
Release: 2016-06-23 13:37:00
Original
1620 people have browsed it

mysql 口字符号怎么处理?

mysql 字段是text的,遇到 口字符号就会自动从这里断开,后面的内容无法入库。使用addslashes函数无效。

口字符号就是比口字细那种,不知道是乱码还是无法显示的字符。


回复讨论(解决方案)

就是图中的这个符号

□ 是你输入的吗?

□ 是你输入的吗?


不是,我复制的,不知道原来是什么,csdn发帖内容也不让带这个字符。所以我只能截图。

□ 是你输入的吗?


是新浪微博的微博内容,通过API接口读取的数据,带有这个符号。

设取到的内容在 $s 中(当然要含有那个字符的)
echo base64_encode($s);
贴出结果

设取到的内容在 $s 中(当然要含有那个字符的)
echo base64_encode($s);
贴出结果



44CQ6IuP55CzVEVBTeiDtuWOn+ibi+eZveWPjemmiPCfmYjwn5mI44CR5pys5p2l6YO96KaB552h5LqG44CC56qB54S25p2l5LqG6IO25Y6f6JuL55m955qE5Y+N6aaI8J+YgvCfmILlpKfljYrlpJznmoTvvIzkvaDov5norqnnvqTph4znmoTnlLfku6PnkIbku6zmgI7kuYjmtLvwn5iz5Y2B5LqU5aSp55qE5pWI5p6c77yM5bCx5piv6L+Z5LmI54mb6YC84pyM54Wn6L+Z5Liq6LaL5Yq/5LiL5Y6777yM5LiA5Liq55aX56iL5LiN5q2i5aSn5LiA5LiqY3Vw5LqG5ZCn8J+Ysei/meWwseaYr+iDtuWOn+ibi+eZveS4uuWVpei/meS5iOeBq+eahOaEv+aEj++8gfCfkYrwn5GK5LiA55aX56iL5peg5pWI6YCA5qy+77yB5bCx5piv5pyJ5bqV5rCU4pyMd2VpeGluOnN1bGluMDkwOA==

$s = '44CQ6IuP55CzVEVBTeiDtuWOn+ibi+eZveWPjemmiPCfmYjwn5mI44CR5pys5p2l6YO96KaB552h5LqG44CC56qB54S25p2l5LqG6IO25Y6f6JuL55m955qE5Y+N6aaI8J+YgvCfmILlpKfljYrlpJznmoTvvIzkvaDov5norqnnvqTph4znmoTnlLfku6PnkIbku6zmgI7kuYjmtLvwn5iz5Y2B5LqU5aSp55qE5pWI5p6c77yM5bCx5piv6L+Z5LmI54mb6YC84pyM54Wn6L+Z5Liq6LaL5Yq/5LiL5Y6777yM5LiA5Liq55aX56iL5LiN5q2i5aSn5LiA5LiqY3Vw5LqG5ZCn8J+Ysei/meWwseaYr+iDtuWOn+ibi+eZveS4uuWVpei/meS5iOeBq+eahOaEv+aEj++8gfCfkYrwn5GK5LiA55aX56iL5peg5pWI6YCA5qy+77yB5bCx5piv5pyJ5bqV5rCU4pyMd2VpeGluOnN1bGluMDkwOA==';$s = base64_decode($s);//echo $s, PHP_EOL;preg_match_all('/./u', $s, $m);//print_r($m[0]);echo bin2hex($m[0][13]);
Copy after login
Copy after login
f09f9988
这是一个 emoji 表情符,需要设置字符集为 utf8mb4 才能进行保存
如果你的 MySQL 版本较低,不支持 utf8mb4 的话,可以通过字符串替换变通一下
入库前
$text = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $text);
Copy after login
Copy after login

出库后再换回来

特殊字符,可以替?一下??理。

$s = '44CQ6IuP55CzVEVBTeiDtuWOn+ibi+eZveWPjemmiPCfmYjwn5mI44CR5pys5p2l6YO96KaB552h5LqG44CC56qB54S25p2l5LqG6IO25Y6f6JuL55m955qE5Y+N6aaI8J+YgvCfmILlpKfljYrlpJznmoTvvIzkvaDov5norqnnvqTph4znmoTnlLfku6PnkIbku6zmgI7kuYjmtLvwn5iz5Y2B5LqU5aSp55qE5pWI5p6c77yM5bCx5piv6L+Z5LmI54mb6YC84pyM54Wn6L+Z5Liq6LaL5Yq/5LiL5Y6777yM5LiA5Liq55aX56iL5LiN5q2i5aSn5LiA5LiqY3Vw5LqG5ZCn8J+Ysei/meWwseaYr+iDtuWOn+ibi+eZveS4uuWVpei/meS5iOeBq+eahOaEv+aEj++8gfCfkYrwn5GK5LiA55aX56iL5peg5pWI6YCA5qy+77yB5bCx5piv5pyJ5bqV5rCU4pyMd2VpeGluOnN1bGluMDkwOA==';$s = base64_decode($s);//echo $s, PHP_EOL;preg_match_all('/./u', $s, $m);//print_r($m[0]);echo bin2hex($m[0][13]);
Copy after login
Copy after login
f09f9988
这是一个 emoji 表情符,需要设置字符集为 utf8mb4 才能进行保存
如果你的 MySQL 版本较低,不支持 utf8mb4 的话,可以通过字符串替换变通一下
入库前
$text = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $text);
Copy after login
Copy after login

出库后再换回来



多谢,MySQL版本是5.1的,只能替换变通了。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template