MySQL 排序规则或 PHP 端可正确显示重音字母
可以允许存储重音字母并完美解析它们而不会出现任何编码错误的列的最佳排序规则是什么,因为每当我添加重音字母(例如 é、å)时,它都会在 PHP 端显示出编码问题,但在 MySQL 方面,这很好...
如何让重音字母正确显示?
What is the best Collation for the column that can allow to store accented letters and parse them out perfectly without any encoding error, because whenever I add an accented letter such as é, å, it shows out with an encoding problem on the PHP side, but in the MySQL side it's fine...
How do I get the accented letters display properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过匹配两端的编码来正确获取它们,即。 PHP 输出和数据库都应该使用相同的编码。对于欧洲语言,我建议您的脚本和数据库都使用 UTF-8。请记住,您仍然必须使用
SET NAMES 'utf8' COLLATE 'utf8_general_ci'
在 MySQL 中初始化 UTF-8 排序规则(因此在连接到数据库后立即运行此查询,应该没问题)。You get them correctly by matching the encoding on both ends, ie. both your PHP output and your DB should use the same encoding. For European languages I would suggest using UTF-8 for both your scripts and the DB. Just remember that you still have to initialize UTF-8 collation in MySQL using
SET NAMES 'utf8' COLLATE 'utf8_general_ci'
(so run this query just after you make a connection to the DB and you should be ok).也许您的问题不在数据库中,而是在您显示 PHP 内容的内部?您在输出中指定什么内容编码?如果您要输出内容,您可能需要手动发送标头以指定内容为 UTF-8。
例如:
header("Content-Type: text/html; charset=UTF-8");
Perhaps your problem isn't within the database, but within however you're displaying things from PHP? What content encoding are you specifying in your output? You might need to manually send a header to specify that the content is UTF-8 if that's what you're trying to output.
For instance:
header("Content-Type: text/html; charset=UTF-8");