How do I write a command-line interactive PHP script?

后端 未结 9 1901
南旧
南旧 2020-12-23 21:59

I want to write a PHP script that I can use from the command line. I want it to prompt and accept input for a few items, and then spit out some results. I want to do this in

9条回答
  •  死守一世寂寞
    2020-12-23 23:00

    The algorithm is simple:

    until done:
        display prompt
        line := read a command line of input
        handle line
    

    It's very trivial to use an array that maps commands to callback functions that handle them. The entire challenge is roughly a while loop, and two function calls. PHP also has a readline interface for more advanced shell applications.

提交回复
热议问题