PHP 有没有自动转义双引号的配置?
我想知道是否有人知道 PHP 设置可以自动转义双引号。
我的问题是,在我的本地服务器上,我将此字符串发布到服务器:
{"0":{"id":"19","goal":"34"},"1":{"id":"22","goal":"657675"},"2":{"id":"21","goal":"456"}}
并且它工作正常。但是,在生产服务器上,我发布了相同的字符串,当我回显它时,它被更改为:
{\"0\":{\"id\":\"19\",\"goal\":\"34\"},\"1\":{\"id\":\"22\",\"goal\":\"657675\"},\"2\":{\"id\":\"21\",\"goal\":\"456\"}}
我设法通过 string_replace() 调用修复它,但我想知道为什么会发生这种情况。生产服务器和本地服务器使用相同的代码,并更新为使用相同的数据,因此我假设差异一定是由服务器设置引起的,但我从未听说过有这样的设置。
有人经历过这样的事情吗?
I'm wondering if anyone knows of a PHP setting that will automatically escape double quotes.
My issue is that on my local server, i'm posting this string to the server:
{"0":{"id":"19","goal":"34"},"1":{"id":"22","goal":"657675"},"2":{"id":"21","goal":"456"}}
and it works fine. However, on the production server, I post the same string, and when I echo it out it is changed to:
{\"0\":{\"id\":\"19\",\"goal\":\"34\"},\"1\":{\"id\":\"22\",\"goal\":\"657675\"},\"2\":{\"id\":\"21\",\"goal\":\"456\"}}
I managed to fix it with a string_replace() call, but I would like to know why this is happening. The production server and local server are using the same code and were updated to use the same data, so I'm assuming the discrepency must be caused by server settings, but I have never heard of a setting that does that.
Has anyone experienced something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。它称为魔术引号:
http://php.net/manual/en/security.magicquotes。 php
http://php.net/ Manual/en/info.configuration.php#ini.magic-quotes-gpc
您通常希望将其关闭,并根据需要手动处理转义。
Yes. It's called Magic Quotes:
http://php.net/manual/en/security.magicquotes.php
http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
You generally want to turn this off, and manually handle escaping as necessary.
这通常是“魔法引号”的问题。他们是邪恶的,国际海事组织。如果可能的话,您应该禁用它们。
它们旨在保护您免受 SQL 注入攻击,因此禁用它们后要小心。
This is typically an issues with "Magic Quotes". They are evil, IMO. You should disable them if possible.
They are meant to protect you from SQL injection attacks, so be careful after you disable them.
您可以尝试在发布的数据中使用单引号而不是双引号
You could try to use single quotes in the posted data rather than double