title: Is there a PHP function that only adds slashes to double quotes NOT single quotes
body: <p>I am generating JSON with PHP.</p>
  
  <p>I have been using</p>
  
  <pre><code>$string = 'This string has "double quotes"';
  
  echo addslashes($string);
  </code></pre>
  
  <p>outputs: <code>This string has \" double quotes\"</code></p>
  
  <p>Perfectly valid JSON</p>
  
  <p><strong>Unfortunately addslashes also escapes single quotes with catastrophic results for valid JSON</strong></p>
  
  <pre><code>$string = "This string has 'single quotes'";
  
  echo addslashes($string);
  </code></pre>
  
  <p>outputs: <code>This string has \'single quotes\'</code></p>
  
  <p>In short, is there a way to only escape double quotes?</p>