数组中的PHP字符串仅返回第一个字符 [英] PHP String in Array Only Returns First Character
问题描述
在接下来的一周里,我陷入了一个非常缓慢的1条EDGE互联网连接,所以请原谅我,如果我没有花足够的时间研究这一点,但是我只是设置了一个本地服务器进行测试我通常会在Internet上测试的代码,但在本地LAMP安装上似乎无法正常工作.
For the next week, I'm stuck with a sadly very slow 1-bar EDGE internet connection, so forgive me if I didn't spend quite enough time researching this one, but I just set up a local server for testing code that I would normally test over the internet, and it doesn't seem to be working the same way on my local LAMP install.
问题是,当我这样做时:
The issue is, when I do this:
echo strtolower($_REQUEST['page']);
结果是这样的:
files
但是,当我这样做时:
$page['name'] = strtolower($_REQUEST['page']);
echo $page['name'];
结果是这样的:
f
否,这不是错字,它始终仅返回字符串的第一个字母.进行var_dump($page)
将导致string(5) "files"
,但是进行var_dump($page['name'])
将导致string(1) "f"
.我正在使用PHP 5.2.1
.
No, that's not a typo, it consistently returns only the first letter of the string. Doing a var_dump($page)
will result in string(5) "files"
, but doing a var_dump($page['name'])
will result in string(1) "f"
. I'm using PHP 5.2.1
.
这是怎么回事?
推荐答案
您几乎回答了自己的问题. $page
是文件"(如您的第一个var_dump
所示).这可能是由于已弃用的register_globals
或其手动近似导致的.鉴于此,
You pretty much answered your own question. $page
is "files" (as shown by your first var_dump
). This could be caused by the deprecated register_globals
, or a manual approximation thereof. Given that,
$page['files']
是"f".这是因为非数字字符串被隐式转换为0(!).您可以使用以下方法轻松重现此内容:
is "f". This is because non-numeric strings are implicitly converted to 0 (!). You can reproduce this easily with:
$page = 'files';
echo $page['files'];
这篇关于数组中的PHP字符串仅返回第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!