How to indicate the encoding in php

How to set encoding in PHP: learn how to define the encoding of a page using the header() function with an example.

Indicating encoding in PHP

The default encoding used in PHP is the ISO-8859-1 character set also known as Latin-1. This character set is usually appropriate for Western European languages. To indicate a different encoding in a PHP script, the <meta> tag must be used.


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

The above code is used to indicate that the encoding used in the script is UTF-8. This is a common encoding used for non-Western European languages such as Chinese and Japanese. Other encodings such as ISO-8859-2, Shift-JIS and EUC-JP can also be specified in the same way.

It is important to specify the encoding in the script as it can affect how the web page is displayed. Without the correct encoding, the characters may not be displayed correctly or the page may not display at all. Specifying the encoding also helps search engines and other web services to correctly interpret the content of the web page.

For more information on character sets and encodings, please refer to the W3C Character Encoding Standards.

Answers (0)