public static function encodeDomainName($domain): string
    {
        if ('.' === $domain) {
            return chr(0);
        }

        $domain = rtrim($domain, '.').'.';
        $res = '';

        foreach (explode('.', $domain) as $label) {
            $res .= chr(strlen($label)).$label;
        }

        return $res;
    }
public static function encodeDomainName($domain): string
    {
        if ('.' === $domain) {
            return chr(0);
        }

        $domain = rtrim($domain, '.').'.';
        $res = '';

        foreach (explode('.', $domain) as $label) {
            $res .= chr(strlen($label)).$label;
        }

        return $res;
    }
public static function encodeDomainName ( $ domain ) : string { if ( '.' === $ domain ) { return chr ( 0 ) ; } $ domain = rtrim ( $ domain , '.' ) . '.' ; $ res = '' ; foreach ( explode ( '.' , $ domain ) as $ label ) { $ res .= chr ( strlen ( $ label ) ) . $ label ; } return $ res ; }
Encode a domain name as a sequence of labels.

@param $domain

@return string
Encode a domain name as a sequence of labels .