public static function createFromIp(string $ip, string $version = '')
    {
        if ('' !== $version) {
            return new self('[v'.$version.'.'.$ip.']');
        }

        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return new self($ip);
        }

        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return new self('['.$ip.']');
        }

        if (false !== strpos($ip, '%')) {
            [$ipv6, $zoneId] = explode('%', rawurldecode($ip), 2) + [1 => ''];

            return new self('['.$ipv6.'%25'.rawurlencode($zoneId).']');
        }

        throw new SyntaxError(sprintf('`%s` is an invalid IP Host', $ip));
    }
public static function createFromIp(string $ip, string $version = '')
    {
        if ('' !== $version) {
            return new self('[v'.$version.'.'.$ip.']');
        }

        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return new self($ip);
        }

        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return new self('['.$ip.']');
        }

        if (false !== strpos($ip, '%')) {
            [$ipv6, $zoneId] = explode('%', rawurldecode($ip), 2) + [1 => ''];

            return new self('['.$ipv6.'%25'.rawurlencode($zoneId).']');
        }

        throw new SyntaxError(sprintf('`%s` is an invalid IP Host', $ip));
    }
public static function createFromIp ( string $ ip , string $ version = '' ) { if ( '' !== $ version ) { return new self ( '[v' . $ version . '.' . $ ip . ']' ) ; } if ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { return new self ( $ ip ) ; } if ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { return new self ( '[' . $ ip . ']' ) ; } if ( false !== strpos ( $ ip , '%' ) ) { [ $ ipv6 , $ zoneId ] = explode ( '%' , rawurldecode ( $ ip ) , 2 ) + [ 1 => '' ] ; return new self ( '[' . $ ipv6 . '%25' . rawurlencode ( $ zoneId ) . ']' ) ; } throw new SyntaxError ( sprintf ( '`%s` is an invalid IP Host' , $ ip ) ) ; }
Returns a host from an IP address.

@throws SyntaxError If the $ip can not be converted into a Host

@return static
Returns a host from an IP address .