函数名:recode()
函数描述:将字符串从一种字符编码转换为另一种字符编码。
用法: string recode ( string $in_charset , string $out_charset , string $str )
参数:
返回值: 返回转换后的字符串,如果转换失败则返回 FALSE。
注意事项:
示例:
// 转换 ISO-8859-1 编码的字符串为 UTF-8 编码
$str = "Hello, world!";
$converted_str = recode("ISO-8859-1", "UTF-8", $str);
echo $converted_str; // 输出:Hello, world!
// 转换 UTF-8 编码的字符串为 ASCII 编码
$str = "你好,世界!";
$converted_str = recode("UTF-8", "ASCII", $str);
echo $converted_str; // 输出:Ni Hao , Shi Jie !
注意:recode 函数在 PHP 7.4 版本中已被弃用,推荐使用 iconv() 函数来进行字符编码转换。