经典 ASP 文本替换和 UTF-8 编码 [英] Classic ASP text substitution and UTF-8 encoding

查看:27
本文介绍了经典 ASP 文本替换和 UTF-8 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用经典 ASP 的网站.

We have a website that uses Classic ASP.

我们发布过程的一部分会替换文件中的值,我们在其中发现了一个错误,它将文件作为 UTF-8 写出.

Part of our release process substitutes values in a file and we found a bug in it where it will write the file out as UTF-8.

这会导致我们的应用程序开始吐出垃圾.撇号作为一些编码字符返回.

This then causes our application to start spitting out garbage. Apostrophes get returned as some encoded characters.

如果我们随后删除表明此文件为 UTF-8 的 BOM,则之前呈现为垃圾的文本现在可以正确显示.

If we then go an remove the BOM that says this file is UTF-8 then the text that was previously rendered as garbage is now displayed correctly.

在遇到 UTF-8 文件时,IIS 有什么不同的做法吗?

Is there something that IIS does differently when it encounters UTF-8 a file?

推荐答案

UTF-8 不使用 BOM;在某些 Microsoft 软件中,这是一个令人讨厌的错误功能,将它们放在那里.您需要找到发布过程的哪个步骤将 UTF-8 编码的 BOM 放入文件并修复它 — 即使您正在使用 UTF-8,您也应该停止这种情况,现在确实如此最好.

UTF-8 does not use BOMs; it is an annoying misfeature in some Microsoft software that puts them there. You need to find what step of your release process is putting a UTF-8-encoded BOM in your files and fix it — you should stop that even if you are using UTF-8, which really these days is best.

但我怀疑是 IIS 导致了显示问题.浏览器更有可能猜测最终显示页面的字符集,当它看到看起来像是 UTF-8 编码的字节时,它会猜测整个页面是 UTF-8.您应该能够通过使用 HTTP 标头声明明确的字符集来阻止它:

But I doubt it's IIS causing the display problem. More likely the browser is guessing the charset of the final displayed page, and when it sees bytes that look like they're UTF-8 encoded it guesses the whole page is UTF-8. You should be able to stop it doing that by stating a definitive charset by using an HTTP header:

Content-Type: text/html;charset=iso-8859-1

和/或 HTML 中的元元素

and/or a meta element in the HTML

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

现在(假设 ISO-8859-1 实际上是您的数据所在的字符集)它应该显示 OK.但是,如果您的文件在开始时确实有一个 UTF-8 编码的 BOM,那么您现在会在页面中看到它为",这就是这些字节在 ISO-8859-1 中的样子.所以你仍然需要摆脱那个misBOM.

Now (assuming ISO-8859-1 is actually the character set your data are in) it should display OK. However if your file really does have a UTF-8-encoded BOM at the start, you'll now see that as ‘’ in your page, which is what those bytes look like in ISO-8859-1. So you still need to get rid of that misBOM.

这篇关于经典 ASP 文本替换和 UTF-8 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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