Converting character encoding

Introduction ICONV

Iconv is a computer program and a standardized API used to convert between different character encodings.
This module contains an interface to iconv character set conversion facility. With this module, you can turn a string represented by a local character set into the one represented by another character set, which may be the Unicode character set. Supported character sets depend on the iconv implementation of your system. Note that the iconv function on some systems may not work as you expect. In such case, it’d be a good idea to install the » GNU libiconv library. It will most likely end up with more consistent results.

Since PHP 5.0.0, this extension comes with various utility functions that help you to write multilingual scripts. Let’s have a look at the following sections to explore the new features.


UTF-8 (UCS Transformation Format — 8-bit) is a multibyte character encoding for Unicode. Like UTF-16 and UTF-32, UTF-8 can represent every character in the Unicode character set. Unlike them, it is backward-compatible with ASCII and avoids the complications of endianness and byte order marks. For these and other reasons, UTF-8 has become the dominant character encoding for the World-Wide Web, accounting for more than half of all Web pages. The Internet Engineering Task Force (IETF) requires all Internet protocols to identify the encoding used for character data, and the supported character encodings must include UTF-8.

Converting One Character Encoding into Other Character Encoding

iconv –from-code= –to-code= ./oldfile.htm > ./newfile.html
iconv –f –t ./oldfile.csv > ./newfile.csv

Example: If file is customer_import.csv then command as follows:

iconv –from-code=ISO-8859-1 –to-code=UTF-8 ./customer_import.csv > ./newfile.csv
iconv –f ISO-8859-1 –t UTF-8 ./customer_import.csv > ./newfile.csv

Converting One Character Encoding into Other Character Encoding without command

To save a CSV file by using the UTF-8 encoding format, follow these steps:
Open the CSV file by using Notepad.
In Notepad, click the File menu, and then click Save As.
In the Encoding list, select UTF-8, and then click Save.

It solved following issues:
Q. Chinese/Japanese character support problem and Import file preparation problem
Q. can’t import special characters í ñ ü
Q. How to Convert Text File From ISO-8859-15 to UTF-8 Encoding