phpmyadmin+php 俄语
在 phpmyadmin 中,我使用 utf8_unicode_ci 编码存储了一些俄语值。它们在 phpmyadmin 中完美显示。
当我用 php 获取这些值并尝试将它们放入选择的选项中时,就会出现问题,它们显示为“??????”。
我尝试将标头中的编码更改为 iso-8859-1 而不是 utf-8,但它也不起作用。
我也尝试过
mb_convert_encoding($str, 'UTF-8', 'auto');
但没有改变:(
还有其他想法吗?
In phpmyadmin I have stored a few russian values, using utf8_unicode_ci encoding. They are shown perfectly in phpmyadmin.
The problem appears when I get those values with php and I try to put them into options of a select, they are shown as "??????".
I've tried changing the encoding in the headers to iso-8859-1 instead of utf-8 but it doesn't work neither.
I've also tried with
mb_convert_encoding($str, 'UTF-8', 'auto');
but no change :(
Any other idea??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 MySQL 数据库/连接,请在运行查询之前使用
mysql_query("SET NAMES 'utf8'");
,不过更好的选择是 mysql_set_charset()。还要确保您有条目:
在页面的标题部分。
如果您使用 PDO,请将连接更改为:
If you're using a MySQL DB/connection, use
mysql_query("SET NAMES 'utf8'");
before your run your query, though a better alternative is mysql_set_charset().Also ensure you have the entry:
In the header section of your page.
If you're using PDO, change your connection to:
有何用处?将支持俄语字符的正确编码更改为不支持俄语字符的错误编码有什么意义?
为了在页面上实现正确的编码,您必须做两件事:
utf8
是 mysql 行话中的编码名称。Content-type
HTTP 标头,使用header ('Content-type: text/html; charset=utf-8') ;
没有别的。What for? what's the point in changing right encoding that support russian characters to wrong one that doesn't?
In order to achieve proper encoding on your page, you u have to do 2 things:
mysql_set_charset('utf8')
(or similar function of other library if you'r using one) whereutf8
is the name of the encoding in mysql lingo.Content-type
HTTP header, usingheader ('Content-type: text/html; charset=utf-8');
and nothing else.