Home >Backend Development >PHP Tutorial >How Can I Work Around PHP's Automatic Replacement of Dots in Request and Cookie Names?
PHP's Auto-Replacement of Dots in Request and Cookie Names: Is There a Solution?
PHP automatically replaces dots (.) in request and cookie names with underscores (_), a behavior that can be problematic.
Why does PHP do this? According to PHP.net, dots are not valid characters in PHP variable names, as demonstrated in the example below:
$varname.ext; /* invalid variable name */
To avoid this parsing issue, PHP replaces dots with underscores.
Unfortunately, there is no direct way to disable this behavior. The solution is to manually convert the underscores back to dots in your PHP script using string manipulation functions like str_replace:
<?php $request_uri = $_SERVER['REQUEST_URI']; $get_vars = $_GET; // Convert underscores back to dots in GET variables foreach ($get_vars as $key => $value) { $key = str_replace('_', '.', $key); $get_vars[$key] = $value; } // Echo the modified GET variables print_r($get_vars); ?>
In addition to dots, PHP also replaces the following characters with underscores:
The above is the detailed content of How Can I Work Around PHP's Automatic Replacement of Dots in Request and Cookie Names?. For more information, please follow other related articles on the PHP Chinese website!