a few words about web development

Fast PHP WhoIs class - get information about domains

Simple and extendable PHP class
I wrote this post exactly 10 years ago, in 2009. However in 2019 the class still works great. I only updated it to support .MX domains. Enjoy!

This time I want to present my class for getting information from WhoIs database about any domain.
I know there are already classes for it, but I couldn't find anything "nice". There is, for example, http://sourceforge.net/projects/phpwhois/ project, but it's almost 0,5 MB of code. Albert Einstein said: "Make everything as simple as possible, but not simpler" and 0,5 of code for such a simple thing is just way too much.

So- here's the class that is simple (less than 5kB of code). It might not yet support all possible TLDs, but it gives good results for following: com, net, org, de, fr, pl. If you need any other TLD- you can add it a five minutes. Let's say, you want to support *.ttt domains:

1) Create a function named parse_ttt:

private function parse_ttt($data, $domain)


$domainWord = 'Domain Name:';
$keywords = array(    'Domain Name'        => 'domain',
'Name Server'        => 'dns',
'Creation Date'        => 'created',
'Expiration Date'    => 'expires'

return $this->parse($data, $domain, $domainWord, $keywords, true);

2) Run the script. It will print you information from whois server, something like this:

Domain Name: somedomain.ttt
Some junk here: Junk junk
Name Server: ns.somehost.ttt
Name Server: ns.somehost.ttt
Creation Date: 01-02-2006
Expiration Date: 09-09-2019

Now just alter $domainWord and $keywords variables. Variable $domainWord is the word which is before the domain name. In this example it is "Domain Name:". Variable $keywords should "translate" all special words to "known" values (domain, dnc, created, expires).
After you change the variables- remove "print_r($data); ".
Your function should be ready to use.

Usage example:

$w = new Whois;


    [domain] => Array
            [0] => GOOGLE.COM

    [dns] => Array
            [0] => NS1.GOOGLE.COM
            [1] => NS2.GOOGLE.COM
            [2] => NS3.GOOGLE.COM
            [3] => NS4.GOOGLE.COM

    [created] => Array
            [0] => 15-sep-1997

    [expires] => Array
            [0] => 14-sep-2011



J luisNot working for domains .mx
de77After 10 years I updated the class and now it supports .MX domains. Please download Whois_v3.zip.
Bartek Walaszczykany hithub/gitlab repo?
atuldid not provide domain expire details..
Basar GonullerHello, good work, thank you very much. But expiration date does not work. Could you please fix this? Then it will be perfect.
Dasturchihfxghfhfcgb esghsrhtsrth shtrsthrsthsr htsrhsrththdz