Backend Development 2 min read

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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP rawurlencode() Function: Description, Parameters, Return Value, and Examples

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.

BackendPHPURL encodingrfc3986rawurlencode
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

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.