导航首页 » 技术教程 » PHP:iconv()的用法_iconv函数
PHP:iconv()的用法_iconv函数 166 2023-12-15   

iconv

(PHP 4 >= 4.0.5, PHP 5)

iconv — 字符串按要求的字符编码来转换

说明

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

将字符串 strin_charset 转换编码到 out_charset

参数

in_charset

输入的字符集。

out_charset

输出的字符集。

如果你在 out_charset 后添加了字符串 //TRANSLIT,将启用转写(transliteration)功能。这个意思是,当一个字符不能被目标字符集所表示时,它可以通过一个或多个形似的字符来近似表达。 如果你添加了字符串 //IGNORE,不能以目标字符集表达的字符将被默默丢弃。 否则,str 从第一个无效字符开始截断并导致一个 E_NOTICE

str

要转换的字符串。

返回值

返回转换后的字符串, 或者在失败时返回 FALSE

范例

Example #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
This is the Euro symbol '


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103