title: PHP's json_encode does not escape all JSON control characters
body: <p>Is there any reasons why PHP's json_encode function does not escape all <a href="http://www.json.org/" rel="noreferrer">JSON</a> control characters in a string?</p>
  
  <p>For example let's take a string which spans two rows and has control characters (\r \n " / \) in it:</p>
  
  <pre><code>&lt;?php
  $s = &lt;&lt;&lt;END
  First row.
  Second row w/ "double quotes" and backslash: \.
  END;
  
  $s = json_encode($s);
  echo $s;
  // Will output: "First row.\r\nSecond row w\/ \"double quotes\" and backslash: \\."
  ?&gt;
  </code></pre>
  
  <p>Note that carriage return and newline chars are unescaped. Why?</p>
  
  <p>I'm using jQuery as my JS library and it's $.getJSON() function will do fine when you fully, 100% trust incoming data. Otherwise I use JSON.org's library json2.js like everybody else.
  But if you try to parse that encoded string it throws an error:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  JSON.parse(&lt;?php echo $s ?&gt;);  // Will throw SyntaxError 
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And you can't get the data! If you remove or escape \r \n " and \ in that string then JSON.parse() will not throw error.</p>
  
  <p>Is there any existing, good PHP function for escaping control characters. Simple str_replace with search and replace arrays will not work.</p>