HTML表单,字符集和accept-charset属性 [英] HTML form, character sets, and the accept-charset attribute

查看:201
本文介绍了HTML表单,字符集和accept-charset属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML表单是否使用默认字符集?或者是否使用了默认的accept-charset属性?



在我们的在线表单中,我们遇到了一些字符和字符集的问题。



HTML页面设置为使用字符集ISO-8859-1(使用 content 元标记),但没有特定 accept-charset 在表单中设置属性。



后端数据库使用UTF-8编码。 / p>

我不知道为什么这里有两个不同的字符集 - 这个决定是在我的时间之前,并且不能轻易改变。



大多数时候,一切都很顺利。问题出现时,有人输入不包含在ISO-8859字符集中的字符 - 它在浏览器中正确显示,但作为未知实体到达后端。 用户将字符输入不在ISO-8859字符集中的表单中,在将数据发送到服务器时,页面将使用 meta 标记中的字符集;使奇数实体显示在数据库中。这听起来像一个可行的解释,如果是这样,改变HTML页面的内容类型是一个合理的解决方案的问题吗?



干杯。 >

解决方案

浏览器将以与投放网页相同的字符集的输入发送文本。 accept-charset 可能会导致问题,如果您使用它,请确保它与您的网页具有相同的字符集。



它是一个未知实体的原因是因为您的数据库将其视为UTF-8。但是当它回到页面,它只是字节,这次被视为ISO-8859。



但是,如果将文本中的任何数据库的字符串函数视为UTF-8,则可能会导致问题。


Is there a default character set used by HTML forms? Or is there a default accept-charset attribute that is used?

We're experiencing some problems with characters and character sets in our online forms.

The HTML pages are set to use the character set ISO-8859-1 (using a content meta tag), but there is no specific accept-charset attribute set in the forms.

The databases in the back end use UTF-8 encoding.

I'm not sure why there are two different character sets used here - that decision was a bit before my time, and can't be easily changed.

Most of the time, everything runs quite happily. The problem comes when someone enters a character that's not contained in the ISO-8859 character set - it displays correctly in the browser, but comes through to the back end as an unknown entity. Really bizarrely, it then transfers back to the browser correctly.

I've assumed so far that even if a user enters a character into the form that's not in the ISO-8859 charset, the page will use the character set from the meta tag when sending the data to the server; causing the odd entity to be displayed in the database. Does this sound like a feasible explanation, and - if so - would changing the content type of the HTML pages be a reasonable solution to the problem?

Cheers.

解决方案

Browsers will send the text from inputs in the same charset as the page is served. accept-charset can cause problems, if you use it, make sure it has the same charset as your page.

The reason it's an unknown entity is because your database is treating it as UTF-8. But when it comes back to the page, it's just bytes, this time treated as ISO-8859.

However, it may cause problems if you are using any of your database's string functions on the text if it is treating it as UTF-8.

这篇关于HTML表单,字符集和accept-charset属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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