Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

urlencode()

Encode one form or query value using application/x-www-form-urlencoded rules.

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

Syntax

urlencode(string $string): string

Encode one form or query value using application/x-www-form-urlencoded rules. Spaces become plus, a literal plus becomes %2B, and tilde is encoded as %7E. Applying it to an entire query would also encode its separators.

Signature

urlencode(string $string): string

Example output

q=C%2B%2B+notes%7E&page=2

Examples

<?php
echo "q=", urlencode("C++ notes~"), "&page=2";

Result

q=C%2B%2B+notes%7E&page=2

Sources