PHP urldecode Function | URL-Decode a String

PHP urldecode is an inbuilt function in PHP. It decodes a URL-encoded string back to a normal plain text string. In this article, we will discuss the PHP urldecode Function. Also, we will discuss a few examples of using it.

In order to encode a string to make it convenient to pass in a URL, use the PHP urlencode Function.


string urldecode( $string )


The PHP urdecode Function expects only one parameter. The string which you want to decode is the input to the function.

Return Value

The urldecode Function in PHP returns a string after decoding the input string which was made convenient to pass as a query parameter in the URL.


Input: a%3D1%26b%3D2+1
Output: a=1&b=2 1
PHP urldecode Function


Let’s discuss a few examples of using the function.

Example 1: Decode a Simple URL

For instance, you can decode a simple URL using the function like this:


	$url = "";
	echo urlencode($url);


In the above example, the function replaces % and 2 hex characters to their respective characters.


Example 2: Decoding Query Parameters

Similarly, you can decode a string containing query parameters using the function in the same way.


	$url = "a%3D1%26b%3D2+1";
	echo urlencode($url);


In the above example, the function simply decodes url parameters. Also, notice that it converts + to a space.

a=1&b=2 1


In this article, we discussed the PHP decode Function. You can read more about it on the Official PHP Documentation. Additionally, you can read about PHP String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *