Sometimes, we want to set the HTTP header to UTF-8 using PHP which is valid in W3C validator.
In this article, we’ll look at how to set the HTTP header to UTF-8 using PHP which is valid in W3C validator.
How to set the HTTP header to UTF-8 using PHP which is valid in W3C validator?
To set the HTTP header to UTF-8 using PHP which is valid in W3C validator, we call the header
function to set the Content-Type
response headers.
For instance, we write
header('Content-Type: text/html; charset=utf-8');
to call header
to set the Content-Type
response header to text/html
and the charset
to utf-8
to set the returned HTML to have Unicode encoding.
Conclusion
To set the HTTP header to UTF-8 using PHP which is valid in W3C validator, we call the header
function to set the Content-Type
response headers.