PHP 8 reference · String Functions
PHP rawurlencode() Function
Encode a string per RFC 3986: spaces become %20. Use it for URL path segments.
PHP 8 Since 4.0
Syntax
rawurlencode(string $string): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
Return value
The encoded string.
Examples
<?php
$file = "my report (final).pdf";
echo "https://example.com/files/" . rawurlencode($file), "\n";
Output
https://example.com/files/my%20report%20%28final%29.pdf
<?php
echo rawurldecode("my%20report%20%28final%29.pdf"), "\n";
Output
my report (final).pdf
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
encodeURIComponent()· JavaScript
Related
urlencode()· Encode a string for a URL query value: spaces become + and special characters become %XX codes.http_build_query()· Build a URL-encoded query string, such as page=2&sort=name, from an array. Nested arrays become key[]=... pairs.- PHP Strings · tutorial