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

<?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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendrfc3986rawurlencodeurl-encoding
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

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.