Requests_IDNAEncoder8b7c:f320:99b9:690f:4595:cd17:293a:c069punycode_encode( string $input ): string  RFC3492-compliant encoder   Parameters   $input string Required    UTF-8 encoded string to encode      Return string Punycode-encoded string   Source  File: wp-includes/Requests/IDNAEncoder.php. View all references  public static function punycode_encode($input) {
	$output = '';
	// let n = initial_n
	$n = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_INITIAL_N;
	// let delta = 0
	$delta = 0;
	// let bias = initial_bias
	$bias = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_INITIAL_BIAS;
	// let h = b = the number of basic code points in the input
	$h = 0;
	$b = 0; // see loop
	// copy them to the output in order
	$codepoints = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069utf8_to_codepoints($input);
	$extended   = array();

	foreach ($codepoints as $char) {
		if ($char < 128) {
			// Character is valid ASCII
			// TODO: this should also check if it's valid for a URL
			$output .= chr($char);
			$h++;
		}
		// Check if the character is non-ASCII, but below initial n
		// This never occurs for Punycode, so ignore in coverage
		// @codeCoverageIgnoreStart
		elseif ($char < $n) {
			throw new Requests_Exception('Invalid character', 'idna.character_outside_domain', $char);
		}
		// @codeCoverageIgnoreEnd
		else {
			$extended[$char] = true;
		}
	}
	$extended = array_keys($extended);
	sort($extended);
	$b = $h;
	// [copy them] followed by a delimiter if b > 0
	if (strlen($output) > 0) {
		$output .= '-';
	}
	// {if the input contains a non-basic code point < n then fail}
	// while h < length(input) do begin
	$codepointcount = count($codepoints);
	while ($h < $codepointcount) {
		// let m = the minimum code point >= n in the input
		$m = array_shift($extended);
		//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
		// let delta = delta + (m - n) * (h + 1), fail on overflow
		$delta += ($m - $n) * ($h + 1);
		// let n = m
		$n = $m;
		// for each code point c in the input (in order) do begin
		for ($num = 0; $num < $codepointcount; $num++) {
			$c = $codepoints[$num];
			// if c < n then increment delta, fail on overflow
			if ($c < $n) {
				$delta++;
			}
			// if c == n then begin
			elseif ($c === $n) {
				// let q = delta
				$q = $delta;
				// for k = base to infinity in steps of base do begin
				for ($k = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_BASE; ; $k += sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_BASE) {
					// let t = tmin if k <= bias {+ tmin}, or
					//     tmax if k >= bias + tmax, or k - bias otherwise
					if ($k <= ($bias + sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_TMIN)) {
						$t = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_TMIN;
					}
					elseif ($k >= ($bias + sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_TMAX)) {
						$t = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_TMAX;
					}
					else {
						$t = $k - $bias;
					}
					// if q < t then break
					if ($q < $t) {
						break;
					}
					// output the code point for digit t + ((q - t) mod (base - t))
					$digit   = $t + (($q - $t) % (sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_BASE - $t));
					$output .= sel8b7c:f320:99b9:690f:4595:cd17:293a:c069digit_to_char($digit);
					// let q = (q - t) div (base - t)
					$q = floor(($q - $t) / (sel8b7c:f320:99b9:690f:4595:cd17:293a:c069BOOTSTRAP_BASE - $t));
				} // end
				// output the code point for digit q
				$output .= sel8b7c:f320:99b9:690f:4595:cd17:293a:c069digit_to_char($q);
				// let bias = adapt(delta, h + 1, test h equals b?)
				$bias = sel8b7c:f320:99b9:690f:4595:cd17:293a:c069adapt($delta, $h + 1, $h === $b);
				// let delta = 0
				$delta = 0;
				// increment h
				$h++;
			} // end
		} // end
		// increment delta and n
		$delta++;
		$n++;
	} // end

	return $output;
}
   Related  Uses    Uses Description      Requests_Exception8b7c:f320:99b9:690f:4595:cd17:293a:c069__construct() wp-includes/Requests/Exception.php   Create a new exception     Requests_IDNAEncoder8b7c:f320:99b9:690f:4595:cd17:293a:c069utf8_to_codepoints() wp-includes/Requests/IDNAEncoder.php   Convert a UTF-8 string to a UCS-4 codepoint array     Requests_IDNAEncoder8b7c:f320:99b9:690f:4595:cd17:293a:c069igit_to_char() wp-includes/Requests/IDNAEncoder.php   Convert a digit to its respective character     Requests_IDNAEncoder8b7c:f320:99b9:690f:4595:cd17:293a:c069pt() wp-includes/Requests/IDNAEncoder.php   Adapt the bias   
   Used By    Used By Description      Requests_IDNAEncoder8b7c:f320:99b9:690f:4595:cd17:293a:c069to_ascii() wp-includes/Requests/IDNAEncoder.php   Convert a UTF-8 string to an ASCII string using Punycode   
  

    
{'path': 'public/docs/wordpress/classes/requests_idnaencoder/punycode_encode.html', 'source': 'DevDocs.IO'}