How to get the home directory from a PHP CLI script?

前端 未结 13 1059
生来不讨喜
生来不讨喜 2020-12-08 03:45

From the command line, I can get the home directory like this:

~/

How can I get the home directory inside my PHP CLI script?



        
13条回答
  •  無奈伤痛
    2020-12-08 04:16

    Depends on where you are and what you're trying to do.

    $_SERVER is completely unreliable for a non-server script, BUT $_ENV['HOME'] might be better for a standard shell script. You can always print_r( $GLOBALS ) and see what your environment gives you to play with. phpinfo() also spits out plaintxt when called from a CLI script, and just good ole php -i executed from a shell will do the same.

提交回复
热议问题