Skip to content

Commit 9cc91d4

Browse files
authored
Merge pull request #17 from misagh/master
Sync and Add Another Script
2 parents 693ecce + 6666311 commit 9cc91d4

File tree

3 files changed

+71870
-5359
lines changed

3 files changed

+71870
-5359
lines changed

scripts/update-top-level-domains.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env php
2+
3+
<?php
4+
5+
/*
6+
* To update top level domains from the command line run:
7+
* $ ./update-top-level-domains.php
8+
*/
9+
10+
$topLevelDomainsLocation = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt';
11+
12+
$topLevelDomains = file_get_contents($topLevelDomainsLocation);
13+
14+
if (!is_string($topLevelDomains)) { die('Failed to fetch domains'); }
15+
16+
$topLevelDomains = explode(PHP_EOL, $topLevelDomains);
17+
array_shift($topLevelDomains);
18+
19+
if (!is_array($topLevelDomains)) { die('Unable to parse domains'); }
20+
21+
$exportedArray = '[' . PHP_EOL;
22+
23+
foreach ($topLevelDomains as $domain) {
24+
if (! empty($domain)) {
25+
$domain = strtolower($domain);
26+
$exportedArray .= " '{$domain}'," . PHP_EOL;
27+
}
28+
}
29+
30+
$exportedArray .= ']';
31+
32+
$phpFileTemplate = <<<TEMPLATE
33+
<?php
34+
35+
/**
36+
* @see https://data.iana.org/TLD/tlds-alpha-by-domain.txt
37+
*/
38+
39+
return {$exportedArray};
40+
41+
TEMPLATE;
42+
43+
$writeToFile = file_put_contents('../src/data/top-level-domains.php', $phpFileTemplate);
44+
45+
if (!$writeToFile) { die('Failed to write to file'); }
46+
47+
echo "Successfully Fetched Top Level Domains";
48+
exit();

0 commit comments

Comments
 (0)