Some fixes for domain create and hosts

This commit is contained in:
Pinga 2024-11-23 15:28:41 +02:00
parent 918afc8473
commit abde99e73e
2 changed files with 54 additions and 20 deletions

View file

@ -586,4 +586,20 @@ function toPunycode($value) {
function toUnicode($value) {
// Convert from Punycode to UTF-8 if it's a valid IDN format
return (strpos($value, 'xn--') === 0) ? idn_to_utf8($value, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : $value;
}
function extractHostTLD(string $hostname): array
{
$parts = explode('.', $hostname);
if (count($parts) < 2) {
// Invalid hostname; return empty values
return ['host' => '', 'tld' => ''];
}
// Extract host and TLD
$tld = array_pop($parts); // Get the last part as TLD
$host = array_pop($parts); // Get the second last part as host
return ['host' => $host, 'tld' => $tld];
}