dqkx69935 2010-08-31 03:10 采纳率: 100%
浏览 25
已采纳

仅Array中的PHP字符串返回第一个字符

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']);

the result is this:

files

However, when I do this:

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

the result is this:

f

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.

What is going on here?

Thanks!

Ari

  • 写回答

3条回答 默认 最新

  • douqianzha6213 2010-08-31 03:17
    关注

    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']
    

    is "f". This is because non-numeric strings are implicitly converted to 0 (!). You can reproduce this easily with:

    $page = 'files';
    echo $page['files'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作