编码问题:£磅符号显示为<?>符号 [英] Encoding issue: £ pound symbol appearing as <?> symbol
问题描述
我的数据库字段设置为utf8_general_ci,我的网站编码是utf8。
£符号是黑色钻石,中间有一个问号。
我尝试在数据库中将其更改为& pound;
,它只输出&
我尝试了一个字符串替换:
$ row ['Information'] = str_replace (£,& pound;,$ row ['Information']);
没有什么似乎工作,任何想法?
我尝试在数据库中将其更改为
& pound;
$ b
不要。数据库应包含原始文本,而不是HTML编码的内容。 HTML编码(使用 htmlspecialchars()
)的时间是在输出模板阶段(而不是之前)将一些原始文本插入到HTML中。即使你有这个工作,你只有固定一个字符;其他107025个非ASCII字符仍会中断。
这里显然存在不匹配的编码;您必须确保在任何地方使用相同的编码(最好是UTF-8),特别是:
- 您保存PHP文件的编码in,如果它包含任何非ASCII字符;
- 在输出页面上声明的字符集(通过Content-Type
< meta>
或header()
,最好是两者;如果您只使用< meta>
配置不正确,可以设置自己的charset
覆盖yours); - 数据库中列的编码自己的排序规则,所以只是将其设置在表上是无效的);
- PHP使用的编码与MySQL交谈。这应该使用
mysql_set_charset
设置。
到UTF-8。
My database field is set to utf8_general_ci and my websites encoding is utf8.
The £ symbol is coming up as a black diamond with a question mark through the center.
I tried changing it to £
in the database and it just outputted £
I tried a string replace:
$row['Information'] = str_replace("£", "£", $row['Information']);
Nothing seems to work, any ideas?
I tried changing it to
£
in the database
Don't. The database should contain raw text, never HTML-encoded content. The time to HTML-encode (using htmlspecialchars()
) is when you insert some raw text into HTML at the output templating stage, and not before. Even if you got this to work, you'd only have fixed one character; the other 107025 non-ASCII characters would still break.
Clearly there is a mismatch of encodings here; you must ensure you use the same encoding (preferably UTF-8) everywhere, in particular:
- the encoding you've saved the PHP file in, if it contains any non-ASCII characters;
- the charset declared on the output page (by Content-Type
<meta>
orheader()
, preferably both; if you only use a<meta>
to set it and the server is incorrectly configured it may set its owncharset
overriding yours); - the encoding of the column in the database (each column has its own collation, so just setting it on the table is ineffective);
- the encoding used by PHP to talk to MySQL. This should be set using
mysql_set_charset
.
Unfortunately, none of these settings default to UTF-8.
这篇关于编码问题:£磅符号显示为<?>符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!