Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

rawurlencode

Encodes a string for use in the path of an address.

Syntax

rawurlencode(string $string): string

Parameters

ParameterTypeDescription
$stringstringThe input string.

Return value

stringThe encoded string; a space becomes `%20`.

Examples

Compared with urlencode():

<?php
 
echo rawurlencode('my report.pdf'), "\n";
echo urlencode('my report.pdf');

Output:

my%20report.pdf
my+report.pdf

Notes

For path segments — /files/my%20report.pdf — use rawurlencode(); for parameters after ? urlencode() with its + works too.

See also

In the tutorial

  • HTTP requests and responses — How PHP receives a request and builds a response — the request method and address, headers, status codes, redirects and JSON responses.

Thanks for reading!

Donate to the site — we work hard for you.