处理html输入标记中的utf8编码字符(dealing with utf8 encoded characters in html input tag)
我正在动态添加输入标记的值。 值从服务器返回,在某些情况下,它们是UTF8编码的。 长话短说,输入标签的值仍保留编码字符,例如Sábado给用户。
在我的span标签中,值根据需要呈现,这意味着输出'Sábado'。 我确实用过
我怎样才能解决这个问题?
谢谢。
I'm dynamically adding value of an input tag. The values are returned from the server, and at some cases they are UTF8 encoded. Long story, short, the value of input tags still keeps the encoded characters, rendering e.g. Sábado to the user.
In my span tags, the value is rendered as desired, meaning that 'Sábado' is outputted. I do use
How can I fix this?
thanks.
原文:https://stackoverflow.com/questions/10007026
更新时间:2020-02-20 13:53
最满意答案
这些字符串不是“UTF8编码”,它们是HTML实体 。
不要HTML转义值。 可能你在某个地方双重逃离它们。
如果没有关于代码的详细信息,很难给出更具体的建议。
Those strings are not "UTF8 encoded", those are HTML entities.
Don't HTML escape the values. Possibly you're double-escaping them somewhere.
Hard to give more concrete advise without details about your code.
相关问答
转储文件可能输出为UTF-8,但在导入期间解释为latin1。 ë ,UTF-8的latin1双字节表示,在您的表中作为UTF-8数据。 看到你有完整和破碎数据的混合,这将很难以一般方式修复,但通常,这个肮脏的解决方法*将很好地工作: UPDATE table SET column = REPLACE("ë", "ë", column);
除非您使用的语言不是荷兰语,否则破碎字符的范围应该非常有限,您可以使用少量此类语句来修复它。 有相同问题的相关问题: 检测MySQL中的utf8中断字符
...
作为解决方法使用htmlDocContentDumpOutput()函数。 将文档内容转储到char缓冲区并将缓冲区写入文件。 //htmlSaveFileEnc("modified.html", docPtr, "utf8");
xmlOutputBufferPtr out = xmlAllocOutputBuffer(NULL);
if (out) {
htmlDocContentDumpOutput(out, docPtr, "utf8");
const xmlChar *buffe
...
我不相信这是编码的问题。 您所看到的是未转义的XML字符串。 问题是" 是一个XML转义字符,因此XMLTextReader将为您取消转义。 如果你改变了这个: Example "content" And ─
对此: Example "content" And ─
然后 XmlReader.Value
...
数据在MySQL中存储为UTF-8,但PHP的客户端连接排序规则不是。 这就是为什么你必须在PHP中使用set_charset进行数据库连接。 更新 php.ini :default_charset utf-8 .htaccess :AddDefaultCharset utf-8 The data is stored as UTF-8 in MySQL, but the PHP's client connection collation is not. Which is why you have
...
虽然我不确定如何使用->loadHTMLFile()解决问题,您是否考虑过使用file_get_contents()来获取HTML,对该字符串运行mb_convert_encoding() ,然后将该值传递给->loadHTML() ? 编辑:此外,当你初始化DOMDocument ,你给它的$编码参数? While I'm not sure about how to go about solving the problem with ->loadHTMLFile(), have you cons
...
从JsonConvert.SerializeObject获取输出并通过一个帮助器方法运行它,该方法将所有非ASCII字符转换为它们的转义(“\ uHHHH”)等效字符。 下面给出了一个示例实现。 // Replaces non-ASCII with escape sequences;
// i.e., converts "Tulgôr" to "Tulg\u00f4r".
private static string EscapeUnicode(string input)
{
StringB
...
查看实际存储内容的一种方法是使用HEX功能。 (这是最接近Oracle风格的DUMP()函数的MySQL。 这是一个演示,显示使用HEX函数返回存储的内容...... CREATE TABLE foo
( foo_lat VARCHAR(10) CHARSET latin1
, foo_utf VARCHAR(10) CHARSET utf8
);
INSERT INTO foo (foo_lat, foo_utf) VALUES
( UNHEX('6dc3b1c3b6
...
这些字符串不是“UTF8编码”,它们是HTML实体 。 不要HTML转义值。 可能你在某个地方双重逃离它们。 如果没有关于代码的详细信息,很难给出更具体的建议。 Those strings are not "UTF8 encoded", those are HTML entities. Don't HTML escape the values. Possibly you're double-escaping them somewhere. Hard to give more concrete ad
...
如果您使用的是MySQL,请在DB连接后使用以下内容 mysql_query(“SET NAMES utf8”); 如果您使用的是MySQLi,请在DB连接后使用以下内容 mysqli_set_charset($connection,"utf8");
如果您正在使用mysqli的类和对象,请在下面使用 $mysqli = new mysqli("localhost", "root", "", "test");
$mysqli->set_charset("utf8");
希望这会有所帮助! If
...
我不认为这是允许的: ID和名称标记必须以字母([A-Za-z])开头,后面可以跟随任意数量的字母,数字([0-9]),连字符(“ - ”),下划线(“_”) ,冒号(“:”)和句点(“。”)。 http://www.w3.org/TR/html401/types.html#type-name I don't think this is allowed: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be follow
...