I am generating JSON with PHP.
I have been using
$string = \'This string has \"double quotes\"\'; echo addslashes($string);
output
If you are generating JSON, why not just use the json_encode() function ?