Idn 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程

idn_to_ascii

(PECL idn >= 0.1)

idn_to_asciiConvert UTF-8 encoded domain name to ASCII

说明

string idn_to_ascii ( string $utf8_domain [, int &$errorcode ] )

This function converts a UTF-8 encoded domain name to ASCII according to the IDNA toUnicode() specification. If the input has non-ASCII characters, the output will be in the "xn--" ACE notation.

参数

utf8_domain

The UTF-8 encoded domain name.

Warning

If e.g. an ISO-8859-1 (aka Western Europe latin1) encoded string is passed it will be converted into an ACE encoded "xn--" string. It will not be the one you expected though!

errorcode

Will be set to the IDNA error code.

返回值

The ACE encoded version of the domain name or FALSE in case of an error.

错误/异常

If an error occurs FALSE is returned and the optional errorcode is set. In addition a E_WARNING message is printed.

范例

Example #1 idn_to_ascii() example

First a simple example and then one explaining how to catch errors.

<?php

// ISO-8859-1 encoded string
echo idn_to_ascii(utf8_encode('t?st.de'))); 

// Cannot convert a domain name to ASCII that contains non-ASCII chars but already starts with "xn--"
$ascii idn_to_ascii("xn--".chr(0xC3).chr(0xA4), $errorcode);
if (
$ascii === false) {
    
printf("Detected error %d: %s\n"$errorcodeidn_strerror($errorcode));
}

?>

上例的输出类似于:

xn--tst-qla.de

Detected error 8: Input already contain ACE prefix (`xn--')

参见


Idn 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程