PHP rawurldecode Function and Custom UTF-8 URL Decoding
This article explains PHP's rawurldecode() function for decoding URL‑encoded strings, shows its signature, parameters, return value, provides a simple usage example, notes UTF‑8 considerations, and presents a custom utf8RawUrlDecode() function for handling non‑standard %uXXXX sequences.
PHP provides the rawurldecode() function to decode URL‑encoded strings, converting each “%xx” sequence back to its original character.
The function signature is string rawurldecode ( string $str ) , where $str is the URL to decode, and it returns the decoded string.
Example usage:
The output is // foo bar@baz .
Note: the result of rawurldecode() (and urldecode() ) is UTF‑8 encoded; if the page is not UTF‑8, you must convert the string before displaying.
When the URL contains non‑standard “%unnnn” sequences, the built‑in functions cannot decode them. The article provides a custom utf8RawUrlDecode($source) function that iterates through the string, handles Unicode “%uXXXX” sequences and escaped ASCII “%XX” sequences, builds the decoded string, and returns it.
The custom function uses substr() , hexdec() , chr() , and utf8_encode() to translate the encoded parts into proper characters.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
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.