IdnaEncoder::encode( string|WpOrgRequestsStringable $hostname ): string

In this article

Encode a hostname using Punycode

Parameters

$hostnamestring|WpOrgRequestsStringablerequired
Hostname

Return

string Punycode-encoded hostname

Source

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);
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.