Master PHP’s urldecode(): How to Decode URLs with Simple Code
This article explains the purpose of URL encoding, introduces PHP's urldecode() function, shows its prototype and practical examples, and highlights its limitations and the alternative rawurldecode() for handling special characters.
When developing web applications, you often need to encode and decode URLs. PHP provides built-in functions for this, one of which is urldecode(). This article introduces the usage of urldecode() with example code.
URL encoding replaces disallowed characters (such as spaces, slashes, question marks) with a special 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 string. Its prototype is: string urldecode ( string $str ) Below is a practical example. First, a parameter is encoded using urlencode():
$param = "hello world";
$urlParam = urlencode($param);The variable $urlParam now holds "hello%20world". We then decode it with urldecode():
$decodedParam = urldecode($urlParam);
echo $decodedParam;Running this 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, use the rawurldecode() function instead.
In summary, urldecode() is a useful PHP function for decoding URL‑encoded strings, enabling developers to easily retrieve the original data from encoded URLs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
