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

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

    I know that this is an old question, but if you are looking for an alternative and easy to replicate method across your application, you may consider using a library installed via composer. I've written a library that combine some of the answer here and make it a library and I'll shamelessly promote it here : juliardi/homedir.

    You can install it via composer :

    $ composer require juliardi/homedir
    

    And then use it in your application :

    Hope this answer help you.

提交回复
热议问题