Home > Backend Development > PHP Tutorial > php mysql UTF-8编码有关问题

php mysql UTF-8编码有关问题

WBOY
Release: 2016-06-13 11:55:21
Original
883 people have browsed it

php mysql UTF-8编码问题
有这样一段UTF-8编码 "\xe6\x93\x8d\xe4\xbd\x9c”
在页面里面直接赋值输出时正确的
$subject="\xe6\x93\x8d\xe4\xbd\x9c";
$subject=mb_convert_encoding($subject, "GB2312", "UTF-8");
echo $subject;
?>
但是把条记录放在数据库中,读出转换后 没有改变,输入还是“\xe6\x93\x8d\xe4\xbd\x9c”;
哪位大神遇到过类似问题,请指教,谢谢
------解决方案--------------------
程序中的 "\xe6\x93\x8d\xe4\xbd\x9c"
utf-8编码的 操作 的十六进制内码的一种表示形式(一定是要被双引号括起的)
否则只是 \xe6\x93\x8d\xe4\xbd\x9c 这样的串

只有在程序里书写的才会被转换,外来的都不会
对于字符串 \xe6\x93\x8d\xe4\xbd\x9c 可以这样转换

$s = '\xe6\x93\x8d\xe4\xbd\x9c';<br />echo hex2bin(str_replace('\x', '', $s));<br />echo urldecode(str_replace('\x', '%', $s));
Copy after login

Related labels:
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