PHP, why are you avoiding my quotes?

Possible duplicate:
Why escape characters are added to hidden input value

So, I have a Save.php file.

Two things are required: a file and new content.

You use it by sending a request, such as '/Resources/Save.php?file=/Resources/Data.json&contents={"Hey":"There"}' .

.. but of course url coding. :) I left everything unencoded for simplicity and readability.

The file works, but instead of the content.

 {"Hey":"There"} 

.. I find ..

 {\"Hey\":\"There\"} 

.. which, of course, throws an error when trying to use JSON.parse when receiving a JSON file later through XHR.

To save the contents, I just use ..

 file_put_contents($url, $contents); 

What can I do to get rid of backslashes?

+6
source share
6 answers

Include magic_quotes in PHP.ini.

+8
source

It looks like you have included magic_quotes .

If so, disable it or use the runtime disable function

+4
source

you probably have magic quotes, only two things you can do. disable magic quotes in php.ini or call stripslashes() in $_GET and $_POST global.

FYI, use $_GET['contents'] as opposed to $contents ; newer php versions will not create $contents var.

+3
source

Try the following:

 file_put_contents($url, stripslashes($contents)); 
+3
source

You must disable magic_quotes in the php.ini configuration file. However, if this is not possible, you can also use the stripslashes() function to get rid of automatic escaping.

+2
source

If you cannot turn off magic quotes for your server, you need to check if it is enabled with get_magic_quotes_gpc() and, if true, stripslashes() .

+1
source

Source: https://habr.com/ru/post/890363/


All Articles