What is iconv?
By Jithin on November 11th, 2016
What is iconv
The iconv is a standardized application programming interface (API). It is used to convert character encoding. The conversion is being done with the help of Unicode conversion. In short, the iconv is a computer program that will convert character encoding. Unicode is an international standard used for encoding. It is used with different languages and scripts. In the Unicode method of encoding, each letter, digit or symbol is assigned a unique numeric value that applies across various platforms and programs. The Unicode provides a unique number for every character. This is the working of Unicode encoding.
History of iconv
As we’ve seen, the iconv is a programming interface that will convert character strings from one character encoding to another character encoding in Unix-like operating systems. The iconv was initially used in the HP-UX operating system and it was standardized within the XPG4. It is part of the Single Unix Specification (SUS). The iconv has become popular as every recent Linux distributions contain a free iconv utility implementation. There is also an iconv() function as part of the GNU C library for current Linux systems. This iconv utility is licensed as GPL and so the derivatives must be open in GPL too. For the iconv() function, it is licensed as LGPL and is linkable with closed source applications. This is the main difference with the iconv utility and iconv function.
The GPL and LGPL licenses
The GPL otherwise known as GNU GPL. It stands for GNU General Public License. It is a free software license used worldwide. It guarantees the end users of the product, the freedom to run, study, share and modify the software. The LGPL is GNU Lesser General Public License. It is a free software license published by the Free Software Foundation (FSF). This license allows the developers and companies to use and integrate software released under this license into their own software without being required by the terms of a strong copyleft license to release the source code of their own components.
Iconv PHP Module
There is a PHP Module iconv. This module has an interface to the iconv character set conversion facility. With the help of this module, you can transfer the character set of a string from a local character set to another character set which may be the Unicode character set. The character set supported are completely depends on the iconv implementation of your system. There can be situations where the iconv function may not work properly on some systems. Then you need to install the GNU libiconv library. It used to get more consistent results. Since PHP 5.0.0, this extension comes with various utility functions that will help writing multi-language scripts.
To install the iconv PHP module, you need to have your computer system to be recent POSIX-compliant one. There is standard C library supplied in them. The library should provide iconv facility. If the system is not POSIX-compliant, you need to install the libiconv library to be installed on your system.
The GNU libiconv is a conversion library. There are many computers still operating in locale with a limited character encoding. Some programs are able to convert between a given text encoding and the user’s encoding. Other programs internally store strings in Unicode, to help facilitate internal processing. These programs need to convert between internal string representation (The Unicode) and external string representation (Local encoding) when they do input and output operations. The GNU libiconv is a conversion library for both kinds of applications. The iconv extension is enabled by default. Although it may be disabled when compiling, it has been done with a –without-iconv option. At the time of compilation, the option –with-iconv-dir is used to specify the location of iconv on the system that PHP is being compiled on, otherwise only the default locations only will be scanned. If you are using, PHP 4, you need to enable this extension building with –with-iconv=[DIR]. Also, Windows customers may enable it by having iconv.dll available in the system’s PATH, and php_iconv.dll enabled in php.ini.
For iconv, there are some configuration directives. They are explained below.
1) iconv.input_encoding string
2) iconv.output_encoding string
3) iconv.internal_encoding string
These features have been deprecated as of PHP 5.6.0. According to PHP official website, relying on these features is highly discouraged. These should be left empty by the PHP 5.6 and later users. They need to use default_charset instead.
The iconv installation is described in the following steps.
You can get the source code of the extension from the web. Here are the steps to install libiconv from the web.
2) tar -zxf libiconv-1.9.1.tar.gz
3) cd libiconv-1.9.1
6) make install
The iconv will be installed in /usr/local/bin by default. Now you need to recompile the PHP with the option –with-iconv=/usr/local in the configure options. This is how you can install the iconv on your system.
If you need any further assistance please contact our support department.