PHP Function Reference

PHP rawurldecode() Function



The PHP rawurldecode() function decodes URL-encoded strings. It returns a string in which the sequences with percent (%) signs followed by two hex digits have been replaced with literal characters.

Note: This function does not decode plus symbols + into spaces as urldecode() function does.

Syntax

rawurldecode(string)

Parameters

string Required. Specify the URL to be decoded.

Return Value

Returns the decoded URL, as a string.

Example:

The example below shows the usage of rawurldecode() function.

<?php
$str = "AlphaCodingSkills%20an%20online%20learning%20portal";
$decoded_str = rawurldecode($str);

//displaying the decoded string
echo $decoded_str;
?>

The output of the above code will be:

AlphaCodingSkills an online learning portal

Example:

Consider one more example which shows how a string is encoded and decoded.

<?php
$str1 = "AlphaCodingSkills an online learning portal";
$encoded_str1 = rawurlencode($str1);

echo "The string is: $str1 \n";
echo "Encoded string: $encoded_str1 \n";

$str2 = "AlphaCodingSkills%20an%20online%20learning%20portal";
$decoded_str2 = rawurldecode($str2);

echo "\nThe string is: $str2 \n";
echo "Decoded string: $decoded_str2 \n";
?>

The output of the above code will be:

The string is: AlphaCodingSkills an online learning portal 
Encoded string: AlphaCodingSkills%20an%20online%20learning%20portal 

The string is: AlphaCodingSkills%20an%20online%20learning%20portal 
Decoded string: AlphaCodingSkills an online learning portal 

❮ PHP URLs Reference