title: How do I *PROPERLY* check if a string has a "valid byte sequence" for UTF-8 in PHP?
body: <p>I keep receiving e-mails that are so badly constructed by such incompetent people that it somehow bypasses the PHP check using <strong><em>mb_check_encoding</em></strong>, and thus proceeds to the PostgreSQL INSERT query, which keeps logging this kind of stupid nonsense:</p>
  
  <pre><code>pg_query_params(): Query failed: ERROR:  invalid byte sequence for encoding "UTF8": 0xe4 0x72 0x20:
  </code></pre>
  
  <p>This has been going on for years and has driven me nearly insane.</p>
  
  <p>I can't use PG function hacks. This check must be done in PHP code.</p>
  
  <p>How do I <strong><em>correctly</em></strong> detect if a string contains "invalid byte sequence" in PHP so that I can reject the e-mail as malformed (or "heal" it so that it contains "valid byte sequence")?</p>