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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

rawurlencode(string $string): string

Parameters

ParameterDescription
string The input string.

Return value

The encoded string.

Examples

Encode a path segmentTry it yourself
<?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
Decode itTry it yourself
<?php
echo rawurldecode("my%20report%20%28final%29.pdf"), "\n";

Output

my report (final).pdf

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?