如何防止网页上出现奇怪的字符 [英] How to prevent weird characters from showing up in web pages
问题描述
通常在将字符串从数据库输出到网页时,特殊字符会与其他一些奇怪的字符一起显示(在我的示例中,破折号会变成â€").我该如何预防?
Often when outputting strings from a database onto a webpage, special characters get displayed as some other weird characters (in my example, an em-dash gets turned into â€"). How do I prevent this?
我正在使用PHP + MySQL
,但是我没有使用任何frameworks
.
I'm using PHP + MySQL
, and I'm not using any frameworks
.
我猜想这是由于HTML和数据库之间的编码/字符集不匹配引起的,尽管我不知道如何解决它.
I'm guessing this is caused by mismatched encoding/charset between the HTML and the database, although I can't figure out how to fix it.
推荐答案
在您的html视图页面中使用
in your html view page use
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
,并且如果您要插入其他语言字符代替英语,请将该列设为utf8-general-ci
and if you are inserting some other language character in place of english than make that column utf8-general-ci
这篇关于如何防止网页上出现奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!