PHP | iconv() Function Last Updated : 30 Mar, 2023 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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.Examples: Input : $str = "EURO symbol '€'"; Output : Original :EURO symbol '€' TRANSLIT :EURO symbol 'EUR' IGNORE :EURO symbol '' PLAIN : Input : $str = "Indian rupees '₹'"; Output : Original :Indian rupees '₹' TRANSLIT :Indian rupees 'INR' IGNORE :Indian rupees '' PLAIN : Below programs illustrate the iconv() function in PHP: Program 1: php <?php // Illustrate the iconv() function in php // Input string in Indian Rupees Symbol $str = "Indian Rupees '?' "; // Print original string echo 'Original :', ("$str"), PHP_EOL; // Print translating string echo 'TRANSLIT :', iconv( "UTF-8", "ISO-8859-1//TRANSLIT", $str), PHP_EOL; // Print ignoring symbol echo 'IGNORE :', iconv("UTF-8", "ISO-8859-1//IGNORE", $str), PHP_EOL; // Print plain symbol echo 'PLAIN :', iconv("UTF-8", "ISO-8859-1", $str), PHP_EOL; ?> Output: Original :Indian rupees '₹' TRANSLIT :Indian rupees 'INR' IGNORE :Indian rupees '' PLAIN : Note: PHP Notice: iconv(): Detected an illegal character in input string in /home/90ff059987ef1d6be3414be3dfb0c043.php on line 19 Program 2: php <?php // Input Euro Symbol $str = " EURO '€' "; // Print original string echo 'Original :', ("$str"), PHP_EOL; // Print translating string echo 'TRANSLIT :', iconv( "UTF-8", "ISO-8859-1//TRANSLIT", $str), PHP_EOL; // Print ignoring symbol echo 'IGNORE :', iconv("UTF-8", "ISO-8859-1//IGNORE", $str), PHP_EOL; // Print plain symbol echo 'Plain :', iconv("UTF-8", "ISO-8859-1", $str), PHP_EOL; ?> Output: Original : EURO '€' TRANSLIT : EURO 'EUR' IGNORE : EURO '' PLAIN : Reference: http://php.net/manual/en/function.iconv.php Comment More infoAdvertise with us Next Article PHP | iconv() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP iconv_strlen() Function The iconv_strlen() is an inbuilt function in PHP that is used to calculate the length of a string. It is very useful when your working string is encoded in a different character set, as it can accurately determine the length regardless of the encoding. Syntax:iconv_strlen(string $string, ?string $en 2 min read PHP iconv_substr() Function The icnov_substr() is an inbuilt function in PHP that allows you to extract a portion of a string based on a specified character encoding. Syntax: iconv_substr( string $string, int $offset, ?int $length = null, ?string $encoding = null ): string|falseParameters: This function takes four parameters t 2 min read PHP iconv_strrpos() Function The iconv_strrpos() function is an inbuilt function in PHP that searches for the last occurrence of a substring within a string while taking the character encoding of the string into account. It is similar to the strrpos() function, but it supports multi-byte character sets. Syntax: int|false iconv_ 1 min read PHP | pack() Function The pack() function is an inbuilt function in PHP which is used to pack the given parameter into a binary string in a given format. Syntax: pack( $format, $arguments ) Parameters: This function accepts two parameters as mentioned above and described below: $format: It is required parameter. It speci 2 min read PHP | imagepng() Function The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image. Syntax: bool imagepng( resource $image, int $to, int $qual 2 min read PHP | imagearc() Function The imagearc() function is an inbuilt function in PHP which is used to create an arc of a circle centered at the given coordinates. This function returns true on success or false on failure. Syntax: bool imagearc( $image, $cx, $cy, $width, $height, $start, $end, $color ) Parameters: This function ac 3 min read PHP hebrev() Function The hebrev() function is an inbuilt function in PHP that is used for converting Hebrew text from its logical representation to visual representation, which is commonly used for proper display in web pages and applications. Hebrew text refers to the written or typed content that uses the Hebrew scrip 2 min read PHP | imagechar() Function The imagechar() function is an inbuilt function in PHP which is used to draw a character horizontally. This function draws the first character of string in the image identified by image with its x and y-axis. The coordinate of the top-left corner is (0, 0). Syntax: bool imagechar( $image, $font, $x, 2 min read PHP IntlChar::ord() Function The IntlChar::ord() function is an inbuilt function in PHP which is used to return the Unicode code point value of the given character. Syntax: int IntlChar::ord( $character ) Parameters: This function accepts a single parameter $character which is mandatory. This parameter is a Unicode character. R 2 min read PHP | imagesy() Function The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati 1 min read Like