在mysql数据库中获取值时获取奇怪的字符 [英] Getting weird characters when fetching value in mysql database

查看:110
本文介绍了在mysql数据库中获取值时获取奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中得到这种结果 每次我输入这个字符'

I'm getting this kind of result in my database ’ everytime i'm typing this character

从数据库获取数据时,我已经使用了 mysql_query('SET CHARACTER SET utf8');

I already use mysql_query('SET CHARACTER SET utf8'); when fetching data from my database.

我已经有< html>< head>< meta http-equiv =Content-Typecontent =text / html ; charset = UTF-8/> ..... 这个在我的HTML上。

I already have <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />..... this one on my HTML.

这里还缺什么?

谢谢!

推荐答案

我注意到您正在运行此查询... mysql_query('SET CHARACTER SET utf8');

尝试将其更改为此.. 。

I notice that you're running this query... mysql_query('SET CHARACTER SET utf8');
Try changing that to this...

mysql_query("SET NAMES 'utf8'");

这应该确保连接是UTF-8。

That should ensure that the connection is UTF-8.

还要尝试浏览本文中的项目列表。 。 http://blog.loftdigital.com/blog/php-utf-8- cheatsheet

下面列出了确保您在网站/应用程序中从前到后使用UTF-8,但总体上需要执行的步骤:

Also try going through the list of items on this article... http://blog.loftdigital.com/blog/php-utf-8-cheatsheet
This lists the steps that are needed to make sure you're using UTF-8 from front to back in your site/application but in summary:


  • 检查您是否有PHP的mbstring扩展名,并且在 cb中设置 mb_internal_encoding('UTF-8'); 脚本。

  • 确保在连接到数据库之后运行此MySQL查询 mysql_query(SET NAMES'utf8'); header('Content-type:text / html;');> charset = UTF-8'); 。如果您已经设置 mb_internal_encoding()但对于调试非常有用,则似乎不需要这样做

  • 确保输出编码的HTML网页已设置... < meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>

  • Check you've got PHP's mbstring extension and you have mb_internal_encoding('UTF-8'); set in your script.
  • Make sure you're running this MySQL query after connecting to your database mysql_query("SET NAMES 'utf8'"); which ensures the connection is UTF-8.
  • Set the HTTP header of your output... header('Content-type: text/html; charset=UTF-8');. This doesn't seem to be needed if you've set mb_internal_encoding() above but useful for debugging
  • Make sure the output encoding of your HTML page is set... <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

这篇关于在mysql数据库中获取值时获取奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆