title: ILLEGAL token for line break in JSON response?
body: <p>After sending back some JSON, JavaScript errors out with:</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token ILLEGAL 
  </code></pre>
  
  <p>when I respond with a string with a line break like:</p>
  
  <pre><code>{ "call": "myFunction("&lt;ul&gt;↵    &lt;li&gt;Passwords are case-sensitive, that is the lower-case letter \"a\" is diffe...")" }
  </code></pre>
  
  <p><a href="http://pastebin.com/KYuXjjBd" rel="nofollow">This is the PHP</a> and <a href="http://pastebin.com/U1MzXQw0" rel="nofollow">this is the raw JSON response I get back</a>.</p>
  
  <p>Yes I <strong>do</strong> override some of the JSON after it has been encoded. I've done this so the clientside knows it has to call a function. I will try alternatives to this.</p>
  
  <p>It doesn't error out when I send a response without a line break. <strong>How can I fix the line break?</strong> What should I convert it to? How do I search and replace it? Should I use a special flag when I call <code>json_encode()</code>?</p>
  
  <p>I've tried:</p>
  
  <pre><code>$json = str_replace("\r\n", "\n", $json);
  $json = str_replace("\r",   "\n", $json);
  $json = str_replace("\n",   "\\n", $json);
  </code></pre>