= 4.0.5, PHP 5, PHP 7, PHP 8)iconv — 字符串按要求的字符編碼來轉(zhuǎn)換說明iconv(string $in_charset, string $out_charset, string $str): string將字符串 str 從 in_cha">
(PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8)
iconv — 字符串按要求的字符編碼來轉(zhuǎn)換
$in_charset
, string $out_charset
, string $str
): string
將字符串 str
從 in_charset
轉(zhuǎn)換編碼到 out_charset
。
in_charset
輸入的字符集。
out_charset
輸出的字符集。
如果你在 out_charset
后添加了字符串 //TRANSLIT
,將啟用轉(zhuǎn)寫(transliteration)功能。這個意思是,當一個字符不能被目標字符集所表示時,它可以通過一個或多個形似的字符來近似表達。
如果你添加了字符串 //IGNORE
,不能以目標字符集表達的字符將被默默丟棄。
否則,會導致一個 E_NOTICE
并返回 false
。
//TRANSLIT
運行細節(jié)高度依賴于系統(tǒng)的 iconv() 實現(xiàn)(參見 ICONV_IMPL
)。
據(jù)悉,某些系統(tǒng)上的實現(xiàn)會直接忽略 //TRANSLIT
,所以轉(zhuǎn)換也有可能失敗,out_charset
會是不合格的。
str
要轉(zhuǎn)換的字符串。
返回轉(zhuǎn)換后的字符串, 或者在失敗時返回 false
。
版本 | 說明 |
---|---|
5.4.0 |
這個版本起,字符非法時候會返回 false ,除非在輸出字符里指定了 //IGNORE 。
在之前版本,它會返回一部分字符串。
|
示例 #1 iconv() 例子
<?php
$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;
?>
以上例程的輸出類似于:
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