PHP rawurlencode() Function: Description, Parameters, Return Value, and Examples
The article explains PHP's rawurlencode() function, detailing its RFC 3986‑based URL encoding behavior, syntax, parameter description, return value, and provides two practical examples showing how special characters are percent‑encoded in FTP and HTTP links, along with a note on decoding functions.
PHP's rawurlencode() function encodes a URL according to RFC 3986, converting all non‑alphanumeric characters except -_. into percent‑encoded sequences.
Signature: string rawurlencode(string $str)
Parameter $str is the URL string to be encoded.
The function returns the encoded string, ensuring that characters such as spaces, @, +, % and / are safely represented.
Example 1
';
?>Output:
<a href="ftp://user:foo%20%40%2B%25%[email protected]/x.txt">Example 2
';
?>Output:
<a href="http://example.com/department_list_script/sales%20and%20marketing%2FMiami">Note: rawurldecode() does not decode the plus sign ('+') into a space, whereas urldecode() does.
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.