title: JSON htmlentities javascript
body: <p>I am using an XMLHttpRequest to POST a JSON string to PHP. The JSON object is created in JavaScript and using the JSON2.js from json.org to create an JSON string representing the object.</p>
  
  <p><code>JSON.stringify(object);</code></p>
  
  <p>Whenever the object contains a string which has a special character in it, e.g. é, JavaScript does not give any error but PHP receives an empty array</p>
  
  <p><code>[]</code></p>
  
  <p>Is there a JavaScript function which produces the exact same resutls as the PHP function</p>
  
  <p><code>htmlentities()</code></p>
  
  <p>The data is send via POST, so the following functions</p>
  
  <pre><code>escape()
  encodeURI()
  encodeURIComponent()
  </code></pre>
  
  <p>are a bit overkill.</p>
  
  <p>Thanks!</p>