точка в имени переменной

1 ответ

The reason PHP is converting your variable name from one.txt into one_txt is because dots are not valid in variable names.

For more details, look at the PHP Documentation:

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

You can either account for the change (. to _) and check for $_REQUEST['one_txt'] or you can make your HTML form pass a valid variable name instead.

Edit:

To follow-up on Michael Borgwardt's comment, here's the text from PHP's documentation about handling variables from external sources:

Dots in incoming variable names

Typically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it:


Now, what the parser sees is a variable named $varname, followed by оператор конкатенации строк, с последующим безымянным кольцом (т.е. строка без кавычек, которая не соответствует любые известные ключевые или зарезервированные слова) доб. Очевидно, у этого нет ожидаемый результат.

По этой причине важно обратите внимание, что PHP автоматически заменить любые точки во входящей переменной имена с подчеркиванием.

Это действительно специфическая вещь PHP.

27
ответ дан 5 December 2019 в 04:58
поделиться
Другие вопросы по тегам:

Похожие вопросы: