Tags: charset
Options list below is in the top priority list first sequence when the content is interpreted by browser. Means the first option will take priority over the second one.
1. In HTTP header
Content-Type: text/html; charset=UTF-8
e.g., in PHP page:
<?php header('Content-Type:text/html;charset=UTF-8'); ?>
e.g., in php.ini (this one takes priority over httpd.conf):
default_charset = "utf-8"
e.g., in Apache(httpd.conf):
Default charset parameter to be added when a response content-type is text/plain or text/html
AddDefaultCharset UTF-8
2. File/IO stream header
It is also called BOM(Byte-Order-Marker) at the beginning of some encoding file/stream. e.g., UTF-8′s BOM is “EFBBBF”.
The BOM can indicate which character encoding it is using.
PHP doesn’t like the BOM( e.g. session_start function). You can use tools like UltraEdit save-as to remove BOM.
3. In HTML header
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
HTML5 also allows the following syntax:
<meta charset="utf-8">
XHTML documents have a third option: to express the character encoding via XML declaration
<?xml version="1.0" encoding="ISO-8859-1"?>
<meta http-equiv=”Content-Type”> may be interpreted directly by a browser, like an ordinary HTML tag, or it may be used by the HTTP server to generate corresponding headers when it serves the document.