HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

urlencode

Description

The urlencode of URL for PHP uRL-encodes string.

Syntax

urlencode(
    string $string
): string

Parameters

string

The string to be encoded.

Return

Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the RFC 3986 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs.

Examples

1 · alphanumeric

<?

$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

$return = urlencode($string);

echo $return;
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

2 · non-alphanumeric · not replaced

<?

$string = "-_.";

$return = urlencode($string);

echo $return;
-_.

3 · non-alphanumeric · replaced · %

<?

$string = "~`!@#$%^&*()+={[}]|\:;\"'<,>?/";

$return = urlencode($string);

echo $return;
%7E%60%21%40%23%24%25%5E%26%2A%28%29%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C%3E%3F%2F

4 · non-alphanumeric · replaced · +

<?

$string = " ";

$return = urlencode($string);

echo $return;
+

5 · url

<?

$string = "url to be encoded";

$return = urlencode($string);

echo '<a href="https://osbo.com?arg=' . $return . '">' . $string . '</a>';
<a href="https://osbo.com?arg=url+to+be+encoded">url to be encoded</a>