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

Viewed 69830

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 function ?

Is that possible if yes then how ? Maybe not only php but maybe with some linux commands ?

4 Answers

similarly you could create a function, like python.

$line = input("Please put in a number: ");
if ($line === 20){
    echo true;
} else {
    echo false;
}

function input(string $prompt = null): string
{
    echo $prompt;
    $handle = fopen ("php://stdin","r");
    $output = fgets ($handle);
    return trim ($output);
}
Related