Forum Moderators: coopster
I have a domain checking php script that is called like this whois.php?domain=mydomain.com
can anyone tell me how i can split the value of the domain parameter into 2 different variables. 1 as domain and the other as the extension so that i can print the value of domain just by putting $domain and print the extension type by putting $ext
any help would be appreciated
cheers
<?php
$domain = explode(".", $_GET[domain]);
print "Domain: $domain[0]";
print "<br>";
print "Extension: $domain[1]";
?>
when i put?domain=something.com it works fine, but if there are 2 dots in the domain .e.g .co.uk then it only displays the co
any help would be appreciated.
cheers
or create a static list of domains with subdomains ie:
$tld['uk']['co']=1;
Then when you do your explode ie:
$parts=explode(".",$domain);
if( isset( $tld[$parts[ count($parts-1) ] ] ) ) {
// more logic here.
}
because you cannot always garantee that it will be 1 or 2 levels. ie. Here in Canada we have .ca we also have .on.ca, .qc.ca, .bc.ca and so on for every province. A site could either have a .ca or a .prov.ca. It may be that way for other TLDs. If you want your solutions to work properly then you have to account from this if you deal with the url from the right hand side.
Like I said earlier if the first part of the domain will *always* be the domain name then you can deal with it from the lefthand side. ie everything before the first "." is the domain. Everything after the first "." is the TLD.
daisho.
<?php
$subdomains = array('AC', 'CO', 'GO', 'RE' [ietf.org]); // you fill this!$url='http://www.domain.co.uk'; // or 'domain.co.uk' -- works for either
if (false!== strpos($url, ".")) { // make sure there is a period
$values = explode(".", $url); // separate values on the periods
// use the last two, or last one, depending on what the second to last is:
$ext = (in_array(strtoupper($values[count($values)-2]), $subdomains))
? $values[count($values)-2].'.'.$values[count($values)-1]
: $values[count($values)-1];
} else {
// processing if no periods were found...
}
?>