Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

rawurlencode()

Encode bytes for one RFC 3986 URL component.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

rawurlencode(string $string): string

Encode bytes for one RFC 3986 URL component. Keep unreserved letters, digits, hyphen, underscore, period and tilde, and encode a space as %20. A slash inside one path segment becomes %2F, so apply this function to individual segments when separators must remain.

Signature

rawurlencode(string $string): string

Example output

a%2Bb%20%2F~
/items/red%2Fblue

Examples

<?php
$segment = "a+b /~";
echo rawurlencode($segment), PHP_EOL;
echo "/items/", rawurlencode("red/blue");

Result

a%2Bb%20%2F~
/items/red%2Fblue

Sources