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

前端 未结 13 1080
生来不讨喜
生来不讨喜 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:26

    $_SERVER['HOME'] and getenv('home') did not work for me.

    However, on PHP 5.5+, this worked to give the home directory that the file is located in:

    explode( '/', __FILE__ )[2]
    

提交回复
热议问题