对静态和动态内容使用不同的字符集时,字符打印会发生冲突 [英] Character printing conflicts when using different charsets for static and dynamic content

查看:191
本文介绍了对静态和动态内容使用不同的字符集时,字符打印会发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何解决此编码冲突吗?



注意:我的文件保存为UTF-8文件。 / p>

当我使用:

 < meta http-equiv =' Content-Type'content ='text / html; charset = utf-8'> 

网页在下面显示的字符为正常 page):

 çÇ,ğŞ,şŞ

但是当相同的字符来自DB(使用mysqli编码)时,它们出现异常

   ,  ,  






当我使用:

 < meta http-equiv =Content-Typecontent = text / html; charset = iso-8859-9> 
< meta http-equiv =Content-languagecontent =tr>

网页显示异常下的字符(它们在页面中硬编码):

 ğâ,ıİ,şı

但是当同样的字符来自DB(用mysqli编码)时,它们出现正常

 çÇ,ğĞ,şŞ


解决方案

在阅读由@Mihai给出的帖子之后,我解决了 $ mysqli-> set_charset('utf8mb4'); 保持< meta charset =utf-8> 。就是这样!


Would someone please tell me how to solve this encoding conflict?

Note: My files are saved as UTF-8 files.

When I use:

<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>

Webpage shows chars below as normal (they are hard-coded in the page):

çÇ, ğĞ, şŞ

But when the same characters come from DB (encoded with mysqli) they appear abnormal:

��, ��, ��


When I use:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
<meta http-equiv="Content-language" content="tr">

Webpage shows chars below abnormal (they are hard-coded in the page):

ğâ, ıİ, şı

But when the same characters come from DB (encoded with mysqli) they appear normal:

çÇ, ğĞ, şŞ

解决方案

After reading the post as given by @Mihai above, I solved the problem with $mysqli->set_charset('utf8mb4'); and just kept <meta charset="utf-8">. That's it!

这篇关于对静态和动态内容使用不同的字符集时,字符打印会发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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