to_ascii example


    public static function encode($hostname) {
        if (InputValidator::is_string_or_stringable($hostname) === false) {
            throw InvalidArgument::create(1, '$hostname', 'string|Stringable', gettype($hostname));
        }

        $parts = explode('.', $hostname);
        foreach ($parts as &$part) {
            $part = self::to_ascii($part);
        }

        return implode('.', $parts);
    }

    /** * Convert a UTF-8 text string to an ASCII string using Punycode * * @param string $text ASCII or UTF-8 string (max length 64 characters) * @return string ASCII string * * @throws \WpOrg\Requests\Exception Provided string longer than 64 ASCII characters (`idna.provided_too_long`) * @throws \WpOrg\Requests\Exception Prepared string longer than 64 ASCII characters (`idna.prepared_too_long`) * @throws \WpOrg\Requests\Exception Provided string already begins with xn-- (`idna.provided_is_prefixed`) * @throws \WpOrg\Requests\Exception Encoded string longer than 64 ASCII characters (`idna.encoded_too_long`) */
Home | Imprint | This part of the site doesn't use cookies.