I'll write you a fully functional and robust code (with a cherry on top) if the price is right :-)
but try these, it may save you time (and money!):
http://php.resourceindex.com/Complete_Scripts/Internet_Utilities/
http://php.resourceindex.com/Complete_Scripts/Internet_Utilities/Whois/
The TLD Checker on the first link sounds pretty good. Try it and see!
One thing you should be aware of when writing your own WHOIS script is that recently registred (meaning within the past 10 minutes or the hour) may not show up on a whois server for up to 24 hrs... so you should consider querying multiple whois servers or using one of the root-servers for your query.
-sridhar