Thursday, 28 April 2016

php - json_encode() function adds backslash

I have a PHP Array with the word 's morgens in it. I'm using a function which escapes the single quote, json_encode() adds another backslash to it which causes an error in the SQL code. The parameter JSON_UNESCAPED_SLASHES causes the following error:





Warning: json_encode() expects parameter 2 to be long, string given




The output is as follows, before json_encode():



string(11) "\'s middags"


And after json_encode():




"\\'s middags"


Its equivalent (long, 64) won't work, it doesn't throw an error. How can I prevent json_encode() from adding a backslash?



(Sorry for bad English, it's not my native language)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...