Current Location: Home> Latest Articles> How to Change the Default Character Encoding in PHP.ini

How to Change the Default Character Encoding in PHP.ini

M66 2025-07-08

How to Change Character Encoding Settings in PHP.ini

Character encoding is an essential aspect of PHP development. Proper character encoding settings ensure that data is transmitted and displayed correctly without issues like garbled text. PHP.ini is the core configuration file for PHP, and it contains various global settings, including character encoding. In this article, we will explain how to change the character encoding in PHP.ini.

Locate the PHP.ini File

First, you need to know where the PHP.ini file is located. Typically, the PHP.ini file is found in the PHP installation directory. However, the exact location may vary depending on the PHP version and operating system. You can use the phpinfo() function to find the path to your PHP.ini file.

Edit the Character Encoding Setting in PHP.ini

Once you have located the PHP.ini file, open it with a text editor. In the PHP.ini file, you will find a section related to character encoding. For example:

; Default file encoding

default_charset = "UTF-8"

As shown, the default character encoding is usually set to UTF-8. If you want to change the character encoding, simply modify the value after the equal sign (e.g., to ISO-8859-1).

Restart the Web Server

After editing the PHP.ini file, you must restart the web server for the changes to take effect. The method to restart the server varies depending on the web server you're using. Refer to the documentation for your specific server to learn how to restart it.

Code Example

Here is an example of the character encoding setting in PHP.ini:

; Default file encoding

default_charset = "UTF-8"

With this simple setting, you ensure that PHP processes and displays data using the UTF-8 character encoding. Correct character encoding settings help avoid issues like garbled text and ensure the integrity of your data.

That's all for how to change character encoding settings in PHP.ini. We hope this article helps you resolve any issues with PHP encoding configuration.