为什么不能在每次提交表单后不断对htmlspecialchars()进行编码?看看下面的例子:php htmlspecialchars()从一种形式到另一种形式
<?php $_POST['txt'] = htmlspecialchars($_POST['txt']); ?>
<form method="post">
<input name="txt" value="<?=$_POST['txt'] ?>" />
<input type="submit" name="save" value="test" />
</form>
你可以看到它运行在http://verticalcms.com/htmlspecialchars.php。
现在做以下
1) Type & into the text field
2) Hit the test button once
3) When the page completes post back, hit the test button again
4) When the page completes post back, view the page source code
在输入框中,该值是&放大器;
我期待着& amp;放大器;
为什么不是& amp;放大器; ???
“$ _POST中的值已经被html解码了,以方便起见” - 对不起,但这不是真的当您通过GET发送HTML编码数据或POST,他们将可用“a s“在您的脚本中,不会进行自动解码。 – 2009-02-05 22:00:22
猜猜我误解了这个问题... – soulmerge 2009-02-06 09:26:25