Interactive shell using PHP

后端 未结 8 978
醉话见心
醉话见心 2020-11-29 09:20

Just wondering, is it possible to create an interactive shell, using PHP alone. I mean something like you have with databases, python, etc.

If it is, how?

8条回答
  •  隐瞒了意图╮
    2020-11-29 09:48

    The way I understand your question you just want the PHP interpreter to run on the command line so you that it will evaluate any PHP code that you type. I use that feature of Python all the time to test code snippets. In which case I believe the answer you are looking for is to execute (from the command line):

    php -a
    

    Assuming PHP is in your path this will drop you in to the PHP interpreter, like it does on mine:

    $ php -a
    Interactive shell
    
    php > 
    

    From there you can start to evaluate arbitrary PHP expressions and see the results:

    php > $a = 'abcdef';
    php > echo strlen($a);
    6
    

提交回复
热议问题