iconv

(PHP 4 >= 4.0.5, PHP 5, PHP 7)

iconvConvert string to requested character encoding

Descrierea

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

Performs a character set conversion on the string string from from_encoding to to_encoding.

Parametri

from_encoding

The input charset.

to_encoding

The output charset.

If you append the string //TRANSLIT to to_encoding 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.

Precauţie

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.

Valorile întoarse

Returns the converted string sau false în cazul eșecului.

Exemple

Example #1 iconv() example

<?php
$text 
"This is the Euro symbol '€'.";

echo 
'Original : '$textPHP_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;

?>

Exemplul de mai sus va afișa ceva similar cu:

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