Backend Development 4 min read

How to Use PHP rawurldecode() to Decode URL‑Encoded Strings

This article explains the PHP rawurldecode() function, its syntax, and how it decodes URL‑encoded strings, provides a complete code example with expected output, and highlights the differences between rawurldecode() and urldecode() for proper URL handling in web development.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Use PHP rawurldecode() to Decode URL‑Encoded Strings

When developing web applications, special characters in URLs must be encoded, and sometimes you need to decode them back to their original form. PHP offers a set of functions for URL encoding and decoding, among which rawurldecode() is used to decode strings that were encoded with urlencode() .

The syntax of rawurldecode() is:

string rawurldecode ( string $str )

Here $str is the URL‑encoded string to be decoded, and the function returns the decoded string.

Below is a practical example that demonstrates how to use rawurldecode() :

<?php
$url = "https%3A%2F%2Fwww.example.com%2F%3Fq%3D%D0%B4%D0%BE%D0%B1%D1%80%D1%8B%D0%B9%E6%B1%89%E5%AD%97"; // URL encoded with urlencode()

$decodedUrl = rawurldecode($url);

echo $decodedUrl;
?>

In this script, a URL that has been encoded by urlencode() is stored in $url . The rawurldecode() function then decodes it, and the result is printed with echo . Running the code outputs:

https://www.example.com/?q=добрый汉字

The output shows that the encoded URL has been successfully restored to its original form, including Unicode characters.

It is important to note that rawurldecode() only decodes the special characters defined by the URL encoding standard; it does not process other characters that may appear in query parameters. If you need to decode an entire URL, including plus signs (+) that represent spaces, you should use the urldecode() function instead.

In summary, rawurldecode() is a convenient PHP function for decoding URLs that were encoded with urlencode() , helping developers correctly handle URL parameters during web development.

backendweb developmentphprawurldecodeURL decoding
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.