PHP's Dot Conversion: Understanding and Workarounds
When passing request fields or cookies with periods in their names, PHP automatically replaces them with underscores. This behavior can be a hindrance, and you may want to prevent it.
PHP's Explanation
According to PHP.net, the dot is not a valid character in PHP variable names. To prevent unintended concatenation issues, PHP automatically converts dots in variable names to underscores.
Additional Characters Affected
In addition to dots, PHP also converts the following characters to underscores:
Workarounds
Since you cannot prevent PHP from performing this conversion, you can use a workaround to convert the underscores back to dots. One possible method is using the str_replace function:
$request_uri = str_replace('_', '.', $_SERVER['REQUEST_URI']);
This will replace all occurrences of underscores with dots in the request URI. You can apply the same approach to other name-value pairs (e.g., $_GET, $_POST, $_COOKIE).
The above is the detailed content of How Does PHP Handle Periods in Variable Names, and How Can I Work Around It?. For more information, please follow other related articles on the PHP Chinese website!