PHP Set HTTP header to UTF-8


PHP Set HTTP header to UTF-8: Sometimes we need to set the HTTp header to UTF-8 in php. header() is used to set the HTTp header to UTF-8. The header() sends a raw HTTP header. In this tutorial we are going to explain how you can set the HTTP header to UTF-8 using PHP.


PHP Set HTTP header to UTF-8

Use the header() function and add the charset utf-8 as below –

PHP Set HTTP header to UTF-8:

header('Content-Type: text/html; charset=utf-8');

Now call this before sending any output to the client. Add this at the starting of the page. There should be no blank space before it because it may cause error. You can check the headers already sent or not using the function headers_sent(). For the function headers_sent() you can refer – http://php.net/manual/en/function.headers-sent.php


Advertisements

Add Comment

📖 Read More