Checking Domain Availability with PHP

Hi guys! I’m having some trouble making a script to check a domain’s availability… Here’s what I got:


$fp = fsockopen("whois.opensrs.net",43);
fputs($fp,$domain_name);
while(!feof($fp)) {
echo fgets($fp,1048);
echo "<br />";
} //while
fclose($fp);

That just tell me the “whois” info, and that’s fine but I want to refine the results to: “It’s availabe” and “Sorry, it’s taken”. Any Ideas will be appreciated!