Why PHP is replacing. with underscore if this is the key in $ _GET?

Possible duplicate:
PHP replaces spaces with underscores

Example: test.php? foo.bar = 1

print_r($_GET); // Array ( [foo_bar] => 1 ) 
+4
source share
3 answers

Here is a quote from the PHP manual

Dots in input variable names

As a rule, PHP does not change variable names when they are passed to a script. However, it should be noted that a period (period, full stop) is not a valid character in the name of a PHP variable. For this reason, look:

 <?php $varname.ext; /* invalid variable name */ ?> Now, what the 

parser sees a variable called $ varname, followed by a string concatenation operator, followed by a ban (i.e. an unquoted string that does not match any known key or reserved words) 'ext'. Obviously, this does not have the intended result. For this reason, it is important to note that PHP automatically replaces any dots in the names of incoming variables with underscores.

+8
source

if the register_globals directive is set, the array keys in $ _GET should be used as variable names and periods, spaces, as well as many other characters are not allowed in php variable names. In fear that you have this directive, php replaces these "invalid" characters

+2
source

Information from PHP. Guidance accurate according to the question:

Note: Dots and spaces in variable names are converted to underscores. For example, it becomes $ _REQUEST ["a_b"].

Source: http://php.net/manual/en/language.variables.external.php

+1
source

All Articles