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

To read a line from standard input in php CLI mode, you can do:

$fin = fopen ("php://stdin","r");
$line = fgets($fin);

On older versions of PHP STDIN constant may also work

$line = fgets(STDIN);

To read all the content from input use:

file_get_contents('php://input');

Leave a Comment