简体   繁体   中英

Escaping problem

I send this string in a GET request

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

but get it in PHP as

{\"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)? (Note: I cannot clean it as I have no control over server side.)

Disable magic_quotes : it's deprecated. 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.

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.

You should turn it of in php.ini if possible.

Anyway, if you, for some reasons, cannot turn off this just use 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). Put the following code in the file:

php_flag magic_quotes_gpc Off

Otherwise, you'll need to use stripslashes() every time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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