为什么要将转义字符添加到隐藏输入的值中 [英] Why are escape characters being added to the value of the hidden input

查看:80
本文介绍了为什么要将转义字符添加到隐藏输入的值中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <身体GT; 
< div> <?= $ _POST ['msg']?> < / DIV>
< form id =frmmethod =post>
< input type =hiddenname ='msg'value ='{field0:Im a string,field1:84,field3:so I I}'/> ;
< input type =submitvalue =test/>
< / form>
< / body>

发布表单时,div标签之间会显示以下字符串。


{\field0 \:\Im a string \,
\field1 \:84, \field3 \:\so
I \}


为什么转义字符被添加?
它们是由PHP服务器还是Web客户端添加的?
我可以做任何事情来预防这种情况吗?

有人已经提到了PHP函数stripslashes。我现在使用它,但我想摆脱所有斜线。 解决方案

检查您的PHP配置是否有 magic_quotes_gpc 激活,在这种情况下,PHP服务器会自动为GET / POST / cookie值添加斜杠...


<body>
  <div> <?= $_POST['msg'] ?> </div>
  <form id="frm" method="post">
    <input type="hidden" name='msg' value='{"field0": "Im a string", "field1": 84, "field3": "so am I"}' />
    <input type="submit" value="test" />
  </form>
</body>

When the form is posted, the following string is displayed between the div tags.

{\"field0\": \"Im a string\", \"field1\": 84, \"field3\": \"so am I\"}

Why are the escape characters being added? Are they being added by the PHP server or the web client? Can I do anything to prevent this?

Someone already mentioned the PHP function stripslashes. I'm using it for now but I want to get rid of the slashes all together.

解决方案

Check whether your PHP configuration has magic_quotes_gpc activated, in such case the PHP server automatically adds slashes to GET/POST/cookie values...

这篇关于为什么要将转义字符添加到隐藏输入的值中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆