1

我正在寻找一些帮助来理解字符集的工作方式。这个问题是使用 windows-1252 而不是 UTF-8 的任何错误的延续

我有一个使用...的测试 ColdFusion 站点

<CFHEADER NAME="Content-Type" value="text/html; charset=windows-1252">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

和一个使用...的测试 Oracle DB

NLS_CHARACTERSET: WE8MSWIN1252
NLS_NCHAR_CHARACTERSET: AL16UTF16

根据 windows-1252 字符集,没有平方根符号(alt+251): √ 但我可以将其输入网页表单的字段中,将其保存到数据库,查询并再次显示在屏幕上就好了. 当它在数据库中时,它存储为:&#8730;. 如果它甚至不是字符集的一部分,我该如何输入、存储、查询和显示它?根据字符集,十进制 251 是这样的:Hex:FB | û | 00FB | LATIN SMALL LETTER U WITH CIRCUMFLEX

4

1 回答 1

3

您并没有真正使用页面和数据库字符集之外的字符。

因为页面是 windows-1252 编码的,如果你在表单域中输入 Alt+251 然后发布数据,浏览器会说:

"Hey this char is not apart of windows-1252 and I need to only send back data
 which is in windows-1252, so I will do the best I can and send back the 
 html character code of char &#8730;  -- oh well, I wish I could send back
 1 character, since I cannot I will send back 7."

如果您注意到,这是 windows-1252 字符集中的 7 个不同字符。

如果页面是用多字节字符集编码的,浏览器会发回一些被认为是 1 个字符的东西。

那么如何查询呢?

 select * from tab where field like '%&#8730;%'

你所拥有的是平方根符号的 html 字符:https: //www.google.com/#q=html+character+codes

更新:

这是一篇很好的文章,解释了正在发生的事情:http: //htmlpurifier.org/docs/enduser-utf8.html

 "...once you start adding characters outside of your encoding... 
 [the browser might] replace the character with a character entity reference...."

此外,当您在 Windows 机器上输入 Alt+251 时,它会插入平方根符号,在 Unicode 中它是 U-221A。

按 Alt+251 就像插入 Unicode 的键盘宏一样,它是 U-221A。

于 2014-02-01T21:51:53.690 回答