Re: php on the Command line
| From: | Chris Adams | Date: | Sun, 25 Jun 2000 22:09:37 +0000 |
| Subject: | Re: php on the Command line | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3037@lists.php.net to get a copy of this message | ||
> i understand how argv and argc work, but if someone leaves off a
> required field, or something such as a password , is it possible to stop
> and prompt them ? i know no perl or c, and im fairly efficent in php, so
> i'd like to stick with this.
You could just do something as simple as:
if ($argc != 3) {
die("usage: scriptname username password database");
} else {
list($Username, $Password, $Database) = $argv;
}
If you want the user to be able to enter a value, try using fgets on stdin (See the fopen() docs for
instructions on how to open stdin, stdout, or stderr). It should be somewhat like this:
$stdout = fopen("php://stdout");
$stdin = fopen("php://stdin");
fputs($stdout, "Username: ");
fgets($stdin, $Username);