title: PHP & HTML5: UTF-8 document declaration with <meta> tag or through the header() function?
body: <p>I'm trying to optimize the way my framework handles HTML5 pages generation. Right now, what I do is to insert a <code>&lt;meta charset="utf-8"/&gt;</code> right after the <code>&lt;head&gt;</code> tag, so it's the first element to be specified (so when I pass the <code>&lt;title&gt;</code> tag and the rest of page elements, it's already defined as being encoded in UTF-8).</p>
  
  <p>The problem is I'm reading some books on website performance optimizations, and most of them recommends specifying the encoding through a <code>Content-type</code> declaration, rather than inserting a <code>&lt;meta&gt;</code> block.</p>
  
  <p>The W3C documentation on character encoding detection (section 8.2.2.1) says, essentially, the HTTP headers have priority above any explicit declaration EXCEPT if the user declared an override for the content type through the user agent.</p>
  
  <p>However, the W3C validator (which is why I use to debug my HTML code output) doesn't complaint but warns me about the absence of the <code>&lt;meta charset="utf-8"/&gt;</code> block, thus encouraging me to put it (it says it's specially recommended if the rendered page is to be saved, which is not the case, but still... it confuses me a bit).</p>
  
  <p>The question is... how can I ensure the pages are ALWAYS specified as encoded in UTF-8? Must I declare the HTTP header AND the <code>&lt;meta&gt;</code> tag or just the HTTP header?</p>