Addslashes, mysql_real_escape always adding two slashes?
Posted
by Zach
on Stack Overflow
See other posts from Stack Overflow
or by Zach
Published on 2010-04-15T17:36:01Z
Indexed on
2010/04/15
17:43 UTC
Read the original article
Hit count: 292
php
|addslashes
I'm having an issue with inserting JSON into a database, my intention is to take the variables, json_encode them, remove slashes (from magic_quotes), and then addslashes back in to escape the quotes in {"key":"value"}
Unfortunately, strip_slashes on the encoded string isn't doing anything, and outputs this
{"content":"<p>This string has it\'s downsides</p>","date":1271352514}
I have then tried addslashes, and mysql_real_escape_string, both output
"{\\"content\\":\\"<p>This string has it\\\'s downsides</p>\\",\\"date\\":1271352514}"
I can't work out why it's adding in two slashes? And I'm tearing my hair out over this, everytime I try to stripslashes it leaves one in, and adding slashes adds two. Any help would be hugely appreciated!
© Stack Overflow or respective owner