function Idn::idn_to_ascii
Parameters
string $domainName:
int $options:
int $variant:
array $idna_info:
Return value
string|false
See also
https://www.unicode.org/reports/tr46/#ToASCII
File
-
vendor/
symfony/ polyfill-intl-idn/ Idn.php, line 146
Class
- Idn
- @internal
Namespace
Symfony\Polyfill\Intl\IdnCode
public static function idn_to_ascii($domainName, $options = self::IDNA_DEFAULT, $variant = self::INTL_IDNA_VARIANT_UTS46, &$idna_info = []) {
if (self::INTL_IDNA_VARIANT_2003 === $variant) {
@trigger_error('idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated', \E_USER_DEPRECATED);
}
$options = [
'CheckHyphens' => true,
'CheckBidi' => self::INTL_IDNA_VARIANT_2003 === $variant || 0 !== ($options & self::IDNA_CHECK_BIDI),
'CheckJoiners' => self::INTL_IDNA_VARIANT_UTS46 === $variant && 0 !== ($options & self::IDNA_CHECK_CONTEXTJ),
'UseSTD3ASCIIRules' => 0 !== ($options & self::IDNA_USE_STD3_RULES),
'Transitional_Processing' => self::INTL_IDNA_VARIANT_2003 === $variant || 0 === ($options & self::IDNA_NONTRANSITIONAL_TO_ASCII),
'VerifyDnsLength' => true,
];
$info = new Info();
$labels = self::process((string) $domainName, $options, $info);
foreach ($labels as $i => $label) {
// Only convert labels to punycode that contain non-ASCII code points
if (1 === preg_match('/[^\\x00-\\x7F]/', $label)) {
try {
$label = 'xn--' . self::punycodeEncode($label);
} catch (\Exception $e) {
$info->errors |= self::ERROR_PUNYCODE;
}
$labels[$i] = $label;
}
}
if ($options['VerifyDnsLength']) {
self::validateDomainAndLabelLength($labels, $info);
}
$idna_info = [
'result' => implode('.', $labels),
'isTransitionalDifferent' => $info->transitionalDifferent,
'errors' => $info->errors,
];
return 0 === $info->errors ? $idna_info['result'] : false;
}