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 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. 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 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? 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 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"] Link to comment https://forums.phpfreaks.com/topic/260731-escaping-characters/#findComment-1336388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.