hackalive Posted April 11, 2012 Share Posted April 11, 2012 Hi guys I am encoding JSON in PHP but want to know how to escape ' and " thats in the content? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/ Share on other sites More sharing options...
silkfire Posted April 11, 2012 Share Posted April 11, 2012 Use addslashes() function. Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336327 Share on other sites More sharing options...
hackalive Posted April 11, 2012 Author Share Posted April 11, 2012 cheers Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336328 Share on other sites More sharing options...
hackalive Posted April 11, 2012 Author Share Posted April 11, 2012 And would I ever use stripslashes? Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336369 Share on other sites More sharing options...
Muddy_Funster Posted April 11, 2012 Share Posted April 11, 2012 when magic_quotes are turned on Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336374 Share on other sites More sharing options...
xyph Posted April 11, 2012 Share Posted April 11, 2012 json_encode handles this for you. <?php $array = array( '"value" 1', "doesnt need 'escaping'", 'etc' ); echo json_encode( $array ); ?> Output ["\"value\" 1","doesnt need 'escaping'","etc"] Quote Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.