Skip to content
Advertisement

Dot replaced by underscore while building query string from array

I’d like to know why the dot is replaced by an underscore during this manipulation :

$s = http_build_query([
    "!~.var" => "",
]);

$a = parse_str($s, $r);

echo $s;

print_r($r);

prints :

%21%7E.var=

Array
(
    [!~_var] => 
)

Advertisement

Answer

parse_str() — Parses the string into variables

Variables do not allow having dots inside their name.

$hello.world = 'hello world'; <– would be illegal.

$hello_world = 'hello world'; <– is legal

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement