Monday, February 18, 2019

escaping - PHP adds escape back slashes. How to stop this



Background: I am not a php programmer, and I only know enough to get the web service parts of my iOS apps working.



I am finding that my php is adding backslashes to my text, when I don't want it to. For example if I set up some variables like this:



$directory = "directory/";

$file = "file.jpg"


then I output via a JSON array back to my device:



$directory . $file 


and I get




"directory\/file.jpg"


I have run get_magic_quotes_gpc with in my php and it reports that magic quotes is turned off. I do this this way:



if (get_magic_quotes_gpc()){
//then I send something back in the JSON array to let me know that get_magic_quotes_gpc is on
}



I have tried to use stripslashes() (on either the original variables or the output) and nothing changes.



So how do I stop it from doing this? As it means that I can't tell my php to delete files in specific directories.



thanks in advance


Answer



When you encode your elements do it as so:



json_encode($str, JSON_UNESCAPED_SLASHES);



Using JSON_UNESCAPED_SLASHESshould prevent the addition of unwanted slashes.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...