Using PHP's urldecode() Function: Concepts, Syntax, and Examples
This article explains PHP's urldecode() function, covering URL encoding basics, the function's prototype, usage examples with code demonstrating encoding with urlencode() and decoding back to the original string, and notes on limitations and the alternative rawurldecode() for non‑ASCII characters.
When developing web applications, it is often necessary to encode and decode URLs; PHP provides built‑in functions for this purpose, one of which is urldecode() .
URL encoding replaces characters that are not allowed in URLs (such as spaces, slashes, and 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 original string.
string urldecode ( string $str )The function only takes one parameter—the string to be decoded—and returns the decoded result.
Below is an example. First, a parameter is encoded using urlencode() :
$param = "hello world";
$urlParam = urlencode($param);The resulting $urlParam contains the value "hello%20world". This encoded value is then decoded with urldecode() :
$decodedParam = urldecode($urlParam);
echo $decodedParam;Running the code outputs "hello world", demonstrating that urldecode() successfully converts the encoded URL 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 revert encoded data to its original representation.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.