title: escape strings correctly into JSON data in PHP
body: <p>I have some rather long string containing just about anything that I want to convert to JSON from PHP. Is there a simple way to do this? For example I would like this JSON ouput to work:</p>
  
  <pre><code>&lt;?php
     $var = "hel\"lo";
     $var2 = "hel\nlo";
     echo "[\"".$var."\", \"".$var2."\"]"; // should give me the data: hel"lo and hel&lt;new line&gt;lo
  ?&gt;
  </code></pre>