rawurlencode
Encodes a string for use in the path of an address.
Syntax
rawurlencode(string $string): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The 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.pdfNotes
For path segments — /files/my%20report.pdf — use rawurlencode(); for parameters after ? urlencode() with its + works too.
See also
- urlencode — Encodes a string for use in a URL.
- urldecode — Decodes a string from a URL.
- http_build_query — Builds a URL query string from an array.
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.