简体   繁体   English

转义问题

[英]Escaping problem

I send this string in a GET request 我在GET请求中发送此字符串

{"foo":[{"bo1":"*","bob":"*"}]}

but get it in PHP as 但是用PHP作为

{\"foo\":[{\"bo1\":\"*\",\"bob\":"\*\"}]}

How do I get it as {"foo":[{"bo1":"*","bob":"*"}]} sending it as part of a query string (or how do I send it via GET method to get it properly)? 如何以{"foo":[{"bo1":"*","bob":"*"}]}将其作为查询字符串的一部分发送(或如何通过GET方法将其发送到正确地获得它)? (Note: I cannot clean it as I have no control over server side.) (注意:我无法清理它,因为我无法控制服务器端。)

Disable magic_quotes : it's deprecated. 禁用magic_quotes :已弃用。 If you can't, you can always use stripslashes on the input: 如果不能,则可以始终在输入上使用反斜杠

$goodStr = stripslashes($_GET['badStr']);

Your php config have enabled magic_quotes_gpc , which causes automatic escaping of quotes and double quotes in all _GET, _POST, and _COOKIE superglobals. 您的php配置已启用magic_quotes_gpc ,这会导致所有_GET,_POST和_COOKIE超全局变量中的引号和双引号自动转义。

If you do not need it, turn it off . 如果不需要它,请将其关闭 If you do, then you should probably rewrite the code which relies on this behaviour, as it is depreciated, and will be removed in future verions of php. 如果这样做,那么您可能应该重写依赖于此行为的代码,因为它已被贬值,并将在以后的php版本中删除。

You should turn it of in php.ini if possible. 如果可能,应该在php.ini中将其打开。

Anyway, if you, for some reasons, cannot turn off this just use stripslashes($your_json); 无论如何,如果由于某些原因您无法关闭此功能,请使用stripslashes($ your_json);。

If the server runs on Apache, create a file called .htaccess in the site root (the leading period is part of the filename). 如果服务器在Apache上运行,请在站点根目录中创建一个名为.htaccess的文件(开头是文件名的一部分)。 Put the following code in the file: 将以下代码放入文件中:

php_flag magic_quotes_gpc Off

Otherwise, you'll need to use stripslashes() every time. 否则,您每次都需要使用stripslashes()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM