函数名:idn_to_utf8()
适用版本:PHP 5 >= 5.3.0, PHP 7, PHP 8
用法:string idn_to_utf8 ( string $domain [, int $options = 0 [, int &$errorcode ]] )
说明:idn_to_utf8() 函数将国际化域名(IDN)转换为 UTF-8 编码。它使用 IDN 扩展库实现,该库必须在 PHP 中启用。
参数:
返回值:返回转换后的 UTF-8 编码字符串,如果转换失败则返回 FALSE。
示例:
$domain = 'xn--fsqu00a.xn--fiqz9s';
$options = IDNA_DEFAULT | IDNA_USE_STD3_RULES;
$utf8Domain = idn_to_utf8($domain, $options, $errorcode);
if ($utf8Domain === false) {
echo "转换失败,错误码:$errorcode";
} else {
echo "转换成功:$utf8Domain";
}
以上示例将国际化域名 'xn--fsqu00a.xn--fiqz9s' 转换为 UTF-8 编码。使用了默认选项和 STD3 规则,如果转换成功,则输出转换后的域名,否则输出错误码。