update : 2015.11.03
php.shukuma.com

검색:
 
 
Convert string to requested character encoding

iconv

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

iconvConvert string to requested character encoding

설명

string iconv ( string $in_charset , string $out_charset , string $str )

Performs a character set conversion on the string str from in_charset to out_charset.

인수

in_charset

The input charset.

out_charset

The 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 string to be converted.

반환값

Returns the converted string실패 시 FALSE를 반환합니다.

변경점

버전 설명
5.4.0 Since this version, the function returns FALSE on illegal characters, unless //IGNORE is specified in output charset. Before, it returned partial output string.

예제

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;

?>

위 예제의 출력 예시:

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