You could do this in many ways, the easiest is probably just to run "whois domain.tld" in the shell and then have PHP apply regular expressions on the command output to determine if it is registered or not. There is actually a fairly complete example of this in the user comments on the PHP shell_exec() manual page:
http://php.net/manual/en/function.shell-exec.php
You could do something similar to extract the registrant information when the domain exists, or return a simple "no match" page when the domain is unregistered.