How to set HTTP header to UTF-8 using PHP which is valid in W3C validator?
Use header
to modify the HTTP header:
header('Content-Type: text/html; charset=utf-8');
Note to call this function before any output has been sent to the client. Otherwise the header has been sent too and you obviously can’t change it any more. You can check that with headers_sent
. See the manual page of header
for more information.
First make sure the PHP files themselves are UTF-8 encoded.
The meta tag is ignored by some browser. If you only use ASCII-characters, it doesn't matter anyway.
http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
header('Content-Type: text/html; charset=utf-8');
This is a problem with your web server sending out an HTTP header that does not match the one you define. For instructions on how to make the server send the correct headers, see this page.
Otherwise, you can also use PHP to modify the headers, but this has to be done before outputting any text using this code:
header('Content-Type: text/html; charset=utf-8');
More information on how to send out headers using PHP can be found in the documentation for the header function.