dongxi1879 2010-03-31 14:23
浏览 5
已采纳

$ _SERVER未使用命令行-r选项设置?

When I try to print the $_SERVER variable from a command line php, it thinks $_SERVER is not set.

$ php -r "print_r($_SERVER);"
Warning: print_r() expects at least 1 parameter, 0 given in Command line code on line 1

However, when it's in a file, running it from the command line has it set

$ cat test.php
<?
print_r($_SERVER);

$ php test.php
Array
(
    [TERM] => xterm
    [SHELL] => /bin/bash
    [SSH_CLIENT] => 192.168.1.101 49319 22
    [SSH_TTY] => /dev/pts/0
...

Why?

  • 写回答

2条回答 默认 最新

  • duanmu5039 2010-03-31 14:27
    关注

    You need to escape the $ character on the command line.

    php -r "print_r(\$_SERVER);"
    

    Otherwise the shell will think it's a shell variable called _SERVER (which you don't have set to anything) and so what's actually been run is php -r "print_r();", which is why you get the error "print_r() expects at least 1 parameter, 0 given".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!