src/WhoisClient.php
public function parseServer($server)
    {
        $server = trim($server);

        $server = preg_replace('/\/$/', '', $server);
        $ipTools = new IpTools;
        if ($ipTools->validIpv6($server)) {
            $result = array('host' => "[$server]");
        } else {
            $parsed = parse_url($server);
            if (array_key_exists('path', $parsed) && !array_key_exists('host', $parsed)) {
                $host = preg_replace('/\//', '', $parsed['path']);

                // if host is ipv6 with port. Example: [1a80:1f45::ebb:12]:8080
                if (preg_match('/^(\[[a-f0-9:]+\]):(\d{1,5})$/i', $host, $matches)) {
                    $result = array('host' => $matches[1], 'port' => $matches[2]);
                } else {
                    $result = array('host' => $host);
                }
            } else {
                $result = $parsed;
            }
        }
        return $result;
    }
public function parseServer($server)
    {
        $server = trim($server);

        $server = preg_replace('/\/$/', '', $server);
        $ipTools = new IpTools;
        if ($ipTools->validIpv6($server)) {
            $result = array('host' => "[$server]");
        } else {
            $parsed = parse_url($server);
            if (array_key_exists('path', $parsed) && !array_key_exists('host', $parsed)) {
                $host = preg_replace('/\//', '', $parsed['path']);

                // if host is ipv6 with port. Example: [1a80:1f45::ebb:12]:8080
                if (preg_match('/^(\[[a-f0-9:]+\]):(\d{1,5})$/i', $host, $matches)) {
                    $result = array('host' => $matches[1], 'port' => $matches[2]);
                } else {
                    $result = array('host' => $host);
                }
            } else {
                $result = $parsed;
            }
        }
        return $result;
    }
public function parseServer ( $ server ) { $ server = trim ( $ server ) ; $ server = preg_replace ( '/\/$/' , '' , $ server ) ; $ ipTools = new IpTools ; if ( $ ipTools -> validIpv6 ( $ server ) ) { $ result = array ( 'host' => "[$server]" ) ; } else { $ parsed = parse_url ( $ server ) ; if ( array_key_exists ( 'path' , $ parsed ) && ! array_key_exists ( 'host' , $ parsed ) ) { $ host = preg_replace ( '/\//' , '' , $ parsed [ 'path' ] ) ; // if host is ipv6 with port. Example: [1a80:1f45::ebb:12]:8080 if ( preg_match ( '/^(\[[a-f0-9:]+\]):(\d{1,5})$/i' , $ host , $ matches ) ) { $ result = array ( 'host' => $ matches [ 1 ] , 'port' => $ matches [ 2 ] ) ; } else { $ result = array ( 'host' => $ host ) ; } } else { $ result = $ parsed ; } } return $ result ; }
Parse server string into array with host and port keys

@param $server   server string in various formattes
@return array    Array containing 'host' key with server host and 'port' if defined in original $server string
Parse server string into array with host and port keys