I have several PHP pages echoing out various things into HTML pages with the following code.
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
However, when I validate using the W3C validator it comes up with:
The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the element (utf-8).
I am quite new to PHP, and I was wondering if I could and should change the header for the PHP files to match the HTML files.
Use the header() function before generating any content, e.g.: header('Content-type: text/html; charset=utf-8'); Java Servlets.
PHP does not natively support UTF-8. This is fairly important to keep in mind when dealing with UTF-8 encoded data in PHP.
HTTP messages are encoded with ISO-8859-1 (which can be nominally considered as an enhanced ASCII version, containing umlauts, diacritic and other characters of West European languages). At the same time, the message body can use another encoding assigned in "Content-Type" header.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With