Skip to content

Instantly share code, notes, and snippets.

@mklooss
Created August 20, 2019 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklooss/9b64060b8b64497cf6a15b0be3668661 to your computer and use it in GitHub Desktop.
Save mklooss/9b64060b8b64497cf6a15b0be3668661 to your computer and use it in GitHub Desktop.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://data.iana.org/TLD/tlds-alpha-by-domain.txt");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$list = curl_exec($ch);
curl_close($ch);
$list = str_replace("\r", "", $list);
$list = array_filter((array)explode("\n", $list));
$new = array();
foreach ($list as $_domain)
{
$_domain = trim($_domain);
if (substr($_domain, 0, 1) == '#')
{
continue;
}
$new[] = mb_strtolower($_domain, 'UTF-8');
$new[] = idn_to_utf8(mb_strtolower($_domain, 'UTF-8'));
}
$new = array_filter(array_unique($new));
foreach ($new as $_domain)
{
echo ' ';
echo "'";
echo $_domain;
echo "'";
echo ",\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment