User input in php command line
January 17th, 2007
Ever wondered how to capture the user input when writing php command line scripts ?
<?php
function getInput($msg){
fwrite(STDOUT, "$msg: ");
$varin = trim(fgets(STDIN));
return $varin;
}
?>
The function above is being used by me in certain command line scripts, where I need user responses.

thank you..
This is the kind of code that SHOULD be on the internet. Short, simple, and sweet. Every time I get code from the internet I have to sort out the overly complicated logic, rewrite it and shorten it. Not this time.
Thanks!
@jc
Thanks JC, glad to know that these posts are useful for some one.
without using html or xml how to get the inputs from the user
what crap is this???
This is command line php script and accepting input from the command line. Not much used, but we are using this kind in real big quantitiy even for administrative tasks, and further. Also we have an ldap suite which provides command line remote administration of the ldap servers, virtual box xml interface for controlling virtual box machines all accessible from very modest desktops which even do not have gui installed. See another command line php in action http://youtu.be/30wohPsWBa4
Do you think this is crap http://youtu.be/30wohPsWBa4
This is an application which works directly on the Gnome Terminal, and uses Galileo XML Webservices, totally written in php and run using the php cli interpreter. Though this is not yet production ready, which is not a limitation of PHP, but of me with very poor knowledge in the Focal Point application, tried to simulate as much as I could. The video I agree is of poor presentation as I am very poor at it.