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.
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
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.
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
Vishesh is currently working as a Lead Software Engineer at Naukri.com. He passed out of Delhi College of Engineering in 2016 and likes to play Foosball. He loves traveling and is an exercise freak. His expertise includes Java, PHP, Python, Databases, Design and Architecture.