$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;
}