PHP 有没有自动转义双引号的配置?

发布于 2024-10-03 22:43:28 字数 528 浏览 0 评论 0原文

我想知道是否有人知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听,心雨的声音 2024-10-10 22:43:28

是的。它称为魔术引号:

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.

几味少女 2024-10-10 22:43:28

这通常是“魔法引号”的问题。他们是邪恶的,国际海事组织。如果可能的话,您应该禁用它们

它们旨在保护您免受 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.

灯角 2024-10-10 22:43:28

您可以尝试在发布的数据中使用单引号而不是双引号

You could try to use single quotes in the posted data rather than double

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文