Avoiding duplicate code (PHP)

As a sysadmin, I end up doing some simple ad-hoc programming every once in a while. I'm trying to learn as I go along, so in general, is there anything in the code below that jumps out at you as being bad practise or otherwise unnecessary?

Specifically, the 3 if statements at the end feels like I'm duplicating code unnecessarily. Is there any way to shorten it further without going overboard with complexity?

<?php

define('TAKEN', 'Match: One');
define('AVAIL', 'Match: No Matches');
define('DATAMINE', 'Data mining count exceeded');

$ch = curl_init("http://co.za/cgi-bin/whois.sh?Domain=example");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

$output = curl_exec($ch);

function search_whois($findit) {
        global $output;
        if (strpos($output, $findit) === false)
                    return false;
        if (is_int(strpos($output, $findit)))
                return true;
}

if (search_whois(TAKEN))
        echo "Domain is taken.\n";

if (search_whois(AVAIL))
        echo "Domain is available.\n";

if (search_whois(DATAMINE))
        echo "Blocked for datamining, try again later.\n";

// var_dump($output);

?>
5
задан Xhantar 15 October 2010 в 12:54
поделиться