title: htmlentities, htmlspecialchars, and "invalid multibyte sequence"
body: <p><a href="https://stackoverflow.com/questions/46483/htmlentities-vs-htmlspecialchars">This question</a> tells me</p>
  
  <blockquote>
    <p>htmlentities is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.</p>
  </blockquote>
  
  <p>Sounds like htmlentities is the one I want.</p>
  
  <p>Then <a href="https://stackoverflow.com/questions/3803951/htmlspecialchars-invalid-multibyte-sequence-in-argument">this question</a> tells me I need the "UTF-8" argument to get rid of this error:</p>
  
  <pre><code>Invalid multibyte sequence in argument
  </code></pre>
  
  <p>So, here is my encoding wrapper function (to normalise behaviour across different PHP versions)</p>
  
  <pre><code>function html_entities ($s)
  {
      return htmlentities ($s, ENT_COMPAT /* ENT_HTML401 */, "UTF-8");
  }
  </code></pre>
  
  <p>I am still getting the "multibyte sequence in argument" error.</p>
  
  <p>Here is a sample string which triggers the error, and it's hex encoding:</p>
  
  <blockquote>
    <p>Jigue à Baptiste</p>
  </blockquote>
  
  <pre><code>4a 69 67 75 65 20 e0 20 - 42 61 70 74 69 73 74 65
  </code></pre>
  
  <p>I notice that the à is encoded as 0xe0 but as a <strong>single byte</strong> which is above 0x80. </p>
  
  <p>What am I doing wrong?</p>