utf8_uri_encode

The timeline below displays how wordpress function utf8_uri_encode has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Encodes the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) === 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) === $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 6.1

/**
 * Encodes the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 8.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.8

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 7.5

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 7.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .10

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.7

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 6.7

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 6.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .10

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.6

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.8

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .10

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.5

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.9

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .10

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 3.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .11

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 2.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .20

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 2.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .14

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 1.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .12

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 0.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .20

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 0.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .15

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 9.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .20

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 9.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .19

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 6.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .22

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .30

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 5.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .25

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .30

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .26

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 3.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .30

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 3.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .27

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string             String to encode.
 * @param int    $length                  Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.3

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int    $length Max  length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 2.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .31

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.2

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                if ($value < 224) {
                    $num_octets = 2;
                } elseif ($value < 240) {
                    $num_octets = 3;
                } else {
                    $num_octets = 4;
                }
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                for ($j = 0; $j < $num_octets; $j++) {
                    $unicode .= '%' . dechex($values[$j]);
                }
                $unicode_length += $num_octets * 3;
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 1.5

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .40

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 1.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .34

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 0.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .34

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 4.0

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    mbstring_binary_safe_encoding();
    $string_length = strlen($utf8_string);
    reset_mbstring_encoding();
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 8.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .37

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 7.5

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .40

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 7.4

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: .37

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @param bool   $encode_ascii_characters Whether to encode ascii characters such as < " '
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0, $encode_ascii_characters = false)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            $char = chr($value);
            $encoded_char = $encode_ascii_characters ? rawurlencode($char) : $char;
            $encoded_char_length = strlen($encoded_char);
            if ($length && $unicode_length + $encoded_char_length > $length) {
                break;
            }
            $unicode .= $encoded_char;
            $unicode_length += $encoded_char_length;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}

WordPress Version: 3.7

/**
 * Encode the Unicode values to be used in the URI.
 *
 * @since 1.5.0
 *
 * @param string $utf8_string
 * @param int $length Max length of the string
 * @return string String with Unicode encoded for URI.
 */
function utf8_uri_encode($utf8_string, $length = 0)
{
    $unicode = '';
    $values = array();
    $num_octets = 1;
    $unicode_length = 0;
    $string_length = strlen($utf8_string);
    for ($i = 0; $i < $string_length; $i++) {
        $value = ord($utf8_string[$i]);
        if ($value < 128) {
            if ($length && $unicode_length >= $length) {
                break;
            }
            $unicode .= chr($value);
            $unicode_length++;
        } else {
            if (count($values) == 0) {
                $num_octets = ($value < 224) ? 2 : 3;
            }
            $values[] = $value;
            if ($length && $unicode_length + $num_octets * 3 > $length) {
                break;
            }
            if (count($values) == $num_octets) {
                if ($num_octets == 3) {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
                    $unicode_length += 9;
                } else {
                    $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
                    $unicode_length += 6;
                }
                $values = array();
                $num_octets = 1;
            }
        }
    }
    return $unicode;
}