The iconv() function is an inbuilt function in PHP which is used to convert a string to requested character encoding. The iconv() is an international standard conversion application command-line programming interface which converts different character encodings to other encoding types with the help of Unicode conversion.
The converted module string represented by a local character set or by another character set, which is Unicode character set or other supported character set depend on the iconv implementation on the system.
string iconv ( string $input_charset, string $output_charset, string $str )
Parameters: This function accepts three parameters as mentioned above and described below:
- $input_charset : It is mandatory parameter used to take input characters string set.
- $output_charset : If you append the string // TRANSLIT to out_charset transliteration is activated.
This means that when a character can’t be represented in the target charset, it can be approximated through one or several similarly looking characters.
If you append the string // IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, E_NOTICE is generated and the function will return FALSE.
- $str: The required string which to be converted.
Return Value: If a string is successfully converted into requested character encoding then it returns the converted string, otherwise, return FALSE.
Input : $str = "EURO symbol '€'"; Output : Original :EURO symbol '€' TRANSLIT :EURO symbol 'EUR' IGNORE :EURO symbol '' PLAIN : Input : $str = "Indian Ruppes '₹'"; Output : Original :Indian Ruppes '₹' TRANSLIT :Indian Ruppes 'INR' IGNORE :Indian Ruppes '' PLAIN :
Below programs illustrate the iconv() function in PHP:
Original :Indian Ruppes '₹' TRANSLIT :Indian Ruppes 'INR' IGNORE :Indian Ruppes '' PLAIN :
Note: PHP Notice: iconv(): Detected an illegal character in input string in /home/90ff059987ef1d6be3414be3dfb0c043.php on line 19
Original : EURO '€' TRANSLIT : EURO 'EUR' IGNORE : EURO '' PLAIN :