Skip to content

Instantly share code, notes, and snippets.

@ikarius6
Created November 20, 2014 23:14
Show Gist options
  • Save ikarius6/35da45ed95507b7256f3 to your computer and use it in GitHub Desktop.
Save ikarius6/35da45ed95507b7256f3 to your computer and use it in GitHub Desktop.
<?php
/* Regex generator for valid TLDs - By MrJack*/
$txt = file_get_contents('http://data.iana.org/TLD/tlds-alpha-by-domain.txt');
$tlds = preg_split('/\s+/', $txt);
$valid_tld = array();
foreach($tlds as $tld){
if (! preg_match('/[^a-z]+/i', $tld, $matches)){
if(strlen($tld) > 3){
array_push($valid_tld, strtolower($tld));
}
}
}
echo implode("|",$valid_tld)."|[a-z]{2}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment