iconv()
iconv() — Convert a string from one character encoding to another.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
iconv(string $from_encoding, string $to_encoding, string $string): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $from_encoding | string | The current encoding used to interpret string. |
| $to_encoding | string | The desired encoding of the result. |
| $string | string | The string to be converted. |
Return value
Returns the converted string, or false on failure.
Example
A runnable snippet:
$text = "This is the Euro symbol '€'."; echo 'Original : ', $text, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
Output:
Original : This is the Euro symbol '€'. TRANSLIT : This is the Euro symbol 'EUR'. IGNORE : This is the Euro symbol ''. Plain : Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page iconv() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.