我发布一个隐藏字段,例如值:"这是示例格式"。当以 $_POST['name'] 获得结果时,变量的值被缩减为仅"this"。这意味着去除白银色后的所有东西。有什么想法吗?
PS 我在隐藏字段的值上使用 htmlspecialchars 用格式化数据替换空格,但这无济于事。
PSS 我认为这是我自己的错,因为网上找不到任何关于它的信息,所以很可能没有解决方案。
猜猜你必须转义引号:"
在你的"值"内'"
。
我似乎无法重现您的错误。你能发布你的表单代码吗,也许还有其他问题?
无论我尝试什么,我都得到了一个好的结果,例如:
<form method="post" action="./test.php">
<input type="hidden" value="<?=htmlspecialchars('this is the format')?>" name="test" />
<input type="submit" />
</form>
// Blah blah code, then result
echo $_POST['test']; // gives this is the format
同样,另一种方式,对 AFTER post 进行编码,给出 OK 结果。
<form method="post" action="./test.php">
<input type="hidden" value="this is the format" name="test" />
<input type="submit" />
</form>
// Blah blah code, then result
echo htmlspecialchars($_POST['test']); // gives this is the format