Re: Can PHP take input from the command prompt interactively?
| From: | Dan McCullough | Date: | Sun, 25 Nov 2001 16:21:47 +0000 |
| Subject: | Re: Can PHP take input from the command prompt interactively? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75653@lists.php.net to get a copy of this message | ||
An example for ya
#!/usr/local/bin/php -q
<?php
/*
file name: shellexample.php
created by: dan mccullough
date created: 10/26/01
purpose: just to do a simple shell script that takes the input and places its output on the
screen
For more information contact Dan McCullough at 603.444.9808
To use this on the command line type [root@ns web]# php shellexample.php
then type your line of text.
*/
function read() {
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return $input;
}
print("Please input your text? ");
$input = read();
$string = $input;
$string = preg_replace ("/(.)/", "\\1\n", $string);
print ($string);
?>
--- David Yee <david@coolcomputing.com> wrote:
> Can I write a command line PHP script like the following:
>
> php -q test.php
>
> Output:
>
> ==================
> 1)choice A
> 2)choice B
> 3)choice C
>
> Please enter an option: 1
> ==================
>
> Thanks.
>
> David
>
>
>
=====
Dan McCullough
-------------------------------------------------------------------
"Theres no such thing as a problem unless the servers are on fire!"
h: 603.444.9808
w: McCullough Family
w: At Work
__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1