PHP cli getting input from user and then dumping into variable possible?

后端 未结 3 536
野的像风
野的像风 2020-11-29 19:59

Is it possible to get input from a user using php cli and then dump the input into a variable and then the script goes ahead.

Just like the c++ cin func

3条回答
  •  天命终不由人
    2020-11-29 20:36

    In this example I'm extending Devjar's example. Credits for him for example code. Last code example is simplest and safest in my opinion.

    When you use his code:

    
    

    You should note stdin mode is not binary-safe. You should add "b" to your mode and use following code:

    
    

    Also you can set max charters. This is my personal example. I'll suggest to use this as your code. It's also recommended to use directly STDIN than "php://stdin".

    
    

提交回复
热议问题