Current Location: Home> Function Categories> urldecode

urldecode

Decode the encoded URL string
Name:urldecode
Category:URLs
Programming Language:php
One-line Description:Decode URL-encoded strings

Function name: urldecode()

Applicable version: PHP 4, PHP 5, PHP 7

Function Description: The urldecode() function is used to decode strings encoded by URL.

Syntax: string urldecode ( string $str )

parameter:

  • $str: Required, URL-encoded string to be decoded.

Return value: The decoded string.

Example:

 <?php $url = "https%3A%2F%2Fwww.example.com%2Fpage.php%3Fid%3D123%26name%3DJohn"; $decodedUrl = urldecode($url); echo $decodedUrl; ?>

Output:

 https://www.example.com/page.php?id=123&name=John

Explanation: In the above example, we first define a URL-encoded string $url and then decode it using the urldecode() function. Finally, we output the decoded string $decodedUrl through the echo statement. The decoded string is the original URL string, and the special characters in it are restored to their original form.

Notes:

  • urldecode() function can only decode URL-encoded strings. If the passed parameter is not a URL-encoded string, no operation will be performed and the original string will be returned directly.
  • urldecode() function can only decode the % symbol and be encoded with two hexadecimal numbers. If you encounter other encoding formats, such as the encoding of the + symbol representing spaces, you need to use rawurldecode() function for decoding.
Similar Functions
Popular Articles