Parsing whois data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Parsing whois data

Post by Benjamin »

I have a script which does whois queries to check and see if a domain name is available or not. I ran into a problem with .com domain names. The problem is that the script I am modifying uses the following code to check to see if a domain is available.

Code: Select all

$snip = explode(" ", $whoisresult);

if (trim($snipї0]) == "Whois")
  {
  echo $domain_infoї'complete'] . " is Available";
  }
  else
  {
  echo $domain_infoї'complete'] . " is Not Available";
  }
The problem is that this only works generally. On domain names which return multiple results, the first word is Whois, so the script thinks it's available.
Whois Server Version 1.3

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

TEST.COM.MY
TEST.COM.AU
TEST.COM

To single out one record, look it up with "xxx", where xxx is one of the
of the records displayed above......
Can anyone give me some ideas on how I can get 100% accurate results? And why did the person who wrote this code use the trim function, I would assume since the array is divided by " ", there would be no way it could have whitespace in the string, is this something I can remove?
jeppe
Forum Newbie
Posts: 6
Joined: Sat Mar 29, 2003 3:05 pm

Post by jeppe »

If the structure of the answer is as you say and what you have tested is test.com, you can test for it with a regular expression:
if (preg_match("/(?sim)[\n\r]".addcslashes($domain,".")."[\n\r]/",$whoisresult))
//the text $domain was found on a line by itself.

But I guess there are more wise ways to do the testing (there are a lot of whois-scripts around out there - see http://www.phpclasses.org for example).
Post Reply