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
<?php
echo '<a href="ftp://user:' . rawurlencode('foo @+%/') . '@ftp.example.com/x.txt">';
?>Output:
<a href="ftp://user:foo%20%40%2B%25%[email protected]/x.txt">Example 2
<?php
echo '<a href="http://example.com/department_list_script/' . rawurlencode('sales and marketing/Miami') . '">';
?>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.
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.
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.
