public function encodeString(string $address): string
    {
        $i = strrpos($address, '@');
        if (false !== $i) {
            $local = substr($address, 0, $i);
            $domain = substr($address, $i + 1);

            if (preg_match('/[^\x00-\x7F]/', $local)) {
                throw new AddressEncoderException(sprintf('Non-ASCII characters not supported in local-part os "%s".', $address));
            }

            if (preg_match('/[^\x00-\x7F]/', $domain)) {
                $address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46));
            }
        }

        return $address;
    }
public function encodeString(string $address): string
    {
        $i = strrpos($address, '@');
        if (false !== $i) {
            $local = substr($address, 0, $i);
            $domain = substr($address, $i + 1);

            if (preg_match('/[^\x00-\x7F]/', $local)) {
                throw new AddressEncoderException(sprintf('Non-ASCII characters not supported in local-part os "%s".', $address));
            }

            if (preg_match('/[^\x00-\x7F]/', $domain)) {
                $address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46));
            }
        }

        return $address;
    }
public function encodeString ( string $ address ) : string { $ i = strrpos ( $ address , '@' ) ; if ( false !== $ i ) { $ local = substr ( $ address , 0 , $ i ) ; $ domain = substr ( $ address , $ i + 1 ) ; if ( preg_match ( '/[^\x00-\x7F]/' , $ local ) ) { throw new AddressEncoderException ( sprintf ( 'Non-ASCII characters not supported in local-part os "%s".' , $ address ) ) ; } if ( preg_match ( '/[^\x00-\x7F]/' , $ domain ) ) { $ address = sprintf ( '%s@%s' , $ local , idn_to_ascii ( $ domain , 0 , INTL_IDNA_VARIANT_UTS46 ) ) ; } } return $ address ; }
Encodes the domain part of an address using IDN.

@throws AddressEncoderException If local-part contains non-ASCII characters
Encodes the domain part of an address using IDN .