HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

iconv

Description

The iconv of iconv for PHP converts a string from one character encoding to another.

Syntax

iconv(
    string $from_encoding,
    string $to_encoding,
    string $string
): string|false

Parameters

from_encoding

The current encoding used to interpret string.

to_encoding

The desired encoding of the result.

If the string //TRANSLIT is appended to to_encoding, then transliteration is activated. This means that when a character can't be represented in the target charset, it may be approximated through one or several similarly looking characters.

If the string //IGNORE is appended, characters that cannot be represented in the target charset are silently discarded.

Otherwise, E_NOTICE is generated and the function will return false.

CAUTION: If and how //TRANSLIT works exactly depends on the system's iconv() implementation (cf. ICONV_IMPL). Some implementations are known to ignore //TRANSLIT, so the conversion is likely to fail for characters which are illegal for the to_encoding.

string

The string to be converted.

Return

Returns the converted string, or false on failure.

Examples

1 · from_encoding to_encoding string

<?

$from_encoding = "UTF-8";
$to_encoding = "ISO-8859-1";
$string = "€";

$return = iconv($from_encoding, $to_encoding, $string);

var_export($return);
false

2 · from_encoding to_encoding · TRANSLIT · string

<?

$from_encoding = "UTF-8";
$to_encoding = "ISO-8859-1//TRANSLIT";
$string = "€";

$return = iconv($from_encoding, $to_encoding, $string);

var_export($return);
'EUR'

3 · from_encoding to_encoding · IGNORE · string

<?

$from_encoding = "UTF-8";
$to_encoding = "ISO-8859-1//IGNORE";
$string = "€";

$return = iconv($from_encoding, $to_encoding, $string);

var_export($return);
''