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.

Syntax

string urldecode( $string )

Parameters

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: https%3A%2F%2Fconcatly.com%2F
Output: https://concatly.com/

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

Examples

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:

<?php

	$url = "https%3A%2F%2Fconcatly.com%2F";
	echo urlencode($url);

?>

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

OUTPUT:
https://concatly.com/

Example 2: Decoding Query Parameters

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

<?php

	$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.

OUTPUT:
a=1&b=2 1

Conclusion

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 *