PHP string in array returns only first character

Next week I was stuck with a very slow 1-channel EDGE Internet connection, so forgive me if I don’t spend enough time learning this, but I just set up a local server to test the code that I would normally test over the Internet, and It doesn't seem to work the same with my local LAMP installation.

The problem is when I do this:

echo strtolower($_REQUEST['page']);

The result is the following:

files

However, when I do this:

$page['name'] = strtolower($_REQUEST['page']);
echo $page['name'];

The result is the following:

f

No, this is not a typo, it consistently returns only the first letter of the string. Execution var_dump($page)will result in string(5) "files", but execution var_dump($page['name'])will result in string(1) "f". I use PHP 5.2.1.

What's going on here?

Thank!

Ari

+3
source share
3

. $page - "" ( var_dump). register_globals . ,

$page['files']

- "f". , 0 (!). :

$page = 'files';
echo $page['files'];
+7

var_dump($page) string(5) "files"

, $page , , , , . , , , . casting $string['files'] $string[0], .

, $page, - . , , .

, $page $page['name'], . $page = array().

+1

To summarize: this is a matter of declaring variables. Before using an array, first declare it:

$page = array();

Good luck working with weird server configurations.

0
source

Source: https://habr.com/ru/post/1762396/


All Articles