Backend Development 3 min read

How to Use PHP's urldecode() Function for URL Decoding

This article explains the concept of URL encoding and decoding, introduces PHP's urldecode() function, details its prototype and usage, provides example code for encoding and decoding parameters, highlights limitations with non‑printable characters, and suggests using rawurldecode() when needed.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Use PHP's urldecode() Function for URL Decoding

In web application development, handling URL encoding and decoding is common, and PHP provides built‑in functions for this purpose, such as urldecode() .

URL encoding replaces characters that are not allowed in a URL (e.g., spaces, slashes, question marks) with a percent‑encoded representation, while URL decoding restores the original characters.

The urldecode() function decodes a URL‑encoded string. It accepts a single string argument and returns the decoded result. Its prototype is:

string urldecode ( string $str )

The function takes one parameter—the encoded string—and returns the original string after decoding.

Below is an example that first encodes a parameter using urlencode() and then decodes it with urldecode() :

$param = "hello world";
$urlParam = urlencode($param);

The variable $urlParam now holds the value hello%20world . Decoding it:

$decodedParam = urldecode($urlParam);
echo $decodedParam;

Running the code outputs hello world , demonstrating that urldecode() successfully converts the encoded parameter back to its original form.

Note that urldecode() cannot properly decode non‑printable characters in the range %00–%20 or non‑ASCII characters below %7F. For such cases, the rawurldecode() function should be used.

In summary, urldecode() is a useful PHP function for decoding URL‑encoded strings, enabling developers to easily retrieve original data from encoded parameters.

backend developmentweb developmentPHPURL decodingurldecode
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.