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 PHP, because all my classes and libraries are in PHP, and I just want to make a simple command line interface to a few things.
The prompting and accepting repeated command line inputs is the part that's tripping me up. How do I do this?
The I/O Streams page from the PHP manual describes how you can use STDIN to read a line from the command line:
<?php $line = trim(fgets(STDIN)); // reads one line from STDIN fscanf(STDIN, "%d\n", $number); // reads number from STDIN ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With