尽管启用了编码,但仍强制显示 html 实体

force html entity to display although encoding is enabled

我找不到与此相关的问题,所以我在这里碰碰运气。 有一个闭源软件,用 php 编写,可以清理 html 个实体(我认为使用 htmlspecialchars();)。因此无法将实体显示为  。该软件尝试使用 spaces 拆分字符串。因此,不间断的 space 不应该影响拆分过程,我可以写 string1 string2 并且它应该被解释为一个词。现实情况是,清理编码了不间断的 space 并且不允许对其进行解释。

是否可以绕过 html 实体的清理(可能使用 utf8 字符)以显示不间断的 space 而不是  

我只能输入字符串值,没有修改源的选项。

实际上不需要绕过 html 实体的清理。它是有目的的。

当您必须在服务器 side/other 函数上使用值时,您需要再次将值解码为原始值

在Js中:

decodeHtml('string1 string2')

实例:http://jsfiddle.net/pranavq212/xasjyjtk/1/

function decodeHtml(html) {
    var txt = document.createElement("textarea");
    txt.innerHTML = html;
    return txt.value;
}
document.getElementById('form').onsubmit = function(e) {
    e.preventDefault();
    var input = document.getElementById('input').value;
    var output = decodeHtml(input);
    alert(output);
}
input {
    width: 100%;
    display: block;
}
<form id="form">
    <input type="text" id="input" placeholder="input" value="string1&nbsp;&nbsp;string2">
<input type="submit" value="alert(input)">
</form>

在PHP

htmlspecialchars_decode($str, ENT_NOQUOTES)

详情请参考: http://php.net/manual/en/function.htmlspecialchars-decode.php

您还可以html_entity_decode 将所有 HTML 实体转换为其适用的字符.

有关用法和详细信息,请参阅:http://php.net/manual/en/function.html-entity-decode.php