as far as i saw on the page ,you gave the link of, the thing you are looking for is can be done like this..
first of all, to not to make list too long, just like the example page did, you should have a list of TLDs...
....
$tld["tr"] = "Turkey";
$tld["uk"]= "Great Britain";
....
than,
getenv("REMOTE_HOST");
would give you the data you're looking for..
than the only thing should be done is taking the part from getenv["REMOTE_HOST"] after the last dot and applying to the array and seeing where it matches to..
well, if it doesnt match than, it means two things... one it's not in our list.. two it wasnt possible to resolve it.. it's your choice to what to do about it..
i wasnt much explaining, because this was only to share my idea about the subject..
i hope it helps