fla*_*ash 1 html php jquery html-encode
我有一个 PHP 代码,如下所示,在 POST 调用中,我得到的是加密值而不是字符。例如,进入后Hello World'我得到这个Hello World';而不是Hello World'在控制台上(from Line Z)。
在 中form_validator.php,我使用以下内容:
if (isset($_POST["response"]))
$response = $_POST["response"];
print_r($response);
Run Code Online (Sandbox Code Playgroud)
在 中form.php,我有以下代码:
<form id="acbdef" name="abcdef" action="#" method="post">
<table width="100%" class="wb-tables table">
<tr>
<td>
<?php echo SECRET_RESPONSE;?>:
</td>
<td colspan="2"><input type="text" id="response" name="response" value="" /></td>
</tr>
</table>
</form>
<script>
$("#save").click(function () {
$.post('form_validator.php', $("#abcdef").serialize(), function (data) {
console.log(data); // Line Z
});// end function(data)
});
</script>
Run Code Online (Sandbox Code Playgroud)
在 中config.php,我有以下内容:
$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$_REQUEST = (array) $_POST + (array) $_GET + (array) $_REQUEST;
Run Code Online (Sandbox Code Playgroud)
问题陈述 :
我想知道我需要在上面的 php 代码中进行哪些更改,以便它采用而character itself不是HTML coded apostrophe.
问题出在你config.php有以下行的地方:
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
Run Code Online (Sandbox Code Playgroud)
这将对输入中的单引号和双引号进行 HTML 编码,如清理过滤器一章中所定义:
FILTER_SANITIZE_STRING去除标签并对双引号和单引号进行 HTML 编码,还可以选择去除或编码特殊字符。可以通过设置禁用引号编码
FILTER_FLAG_NO_ENCODE_QUOTES。(自 PHP 8.1.0 起已弃用,请使用htmlspecialchars()。)
如果您不想在各自的 HTML 编码字符串中转换任何单引号或双引号,请使用该标志FILTER_FLAG_NO_ENCODE_QUOTES或不使用FILTER_SANITIZE_STRING过滤器(无论如何,它已被弃用)。