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

rawurlencode

Description

The rawurlencode of URL for PHP uRL-encode according to RFC 3986.

Syntax

rawurlencode(
    string $string
) : string

Parameters

string

The URL 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. This is the encoding described in RFC 3986 for protecting literal characters from being interpreted as special URL delimiters, and for protecting URLs from being mangled by transmission media with character conversions (like some email systems).

Examples

1 · alphanumeric

<?

$string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

$return = rawurlencode($string);

echo $return;
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

2 · non-alphanumeric · not replaced

<?

$string = "-_.~";

$return = rawurlencode($string);

echo $return;
-_.~

3 · non-alphanumeric · replaced

<?

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

$return = rawurlencode($string);

echo $return;
%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%20

4 · url

<?

$string = "url to be encoded";

$return = rawurlencode($string);

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