Phil Powell wrote:
In TCL it would be written this way:
> puts {Do you want to do this (Y/N Enter=N)?}
gets stdin deleteChar
I guess what I need is the PHP equivalent of TCL's gets command (see
http://www.astro.princeton.edu/~rhl/...a1/gets.n.html
for more information)
or perhaps the PHP equivalent of how a Java app would read from
standard in:
> BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
while ((in.readLine() == null)) {}
I checked out the PHP streaming capabilities and I have no clue how to
use them and the manual makes no clear mention of how they can be used
to retrieve from stdin:
http://www.php.net/wrappers.php
Help appreciated, this is driving me nuts!
Thanx
Phil
First, is this an interactive-type system where you are using PHP in
place of VB or sh or an executable? There is a lot missing from this
dialogue. PHP is not a Visual-anything application, it was designed as
an HTML scripting language to create/display dynamic content and present
it in a browser but some are starting to use it as a cli scripting language.
If this is a web-based PHP app, you do not have the same concepts as an
interactive session. What you can do to mimick this behavior (ie "Do
you really want to..") is to display the results of the fields entered
on a "verification" page and continue if everything looks correct -
executing the form.
Web-based (where your browser is your viewer) pages are static - in that
they stand alone and do not have interaction with the system unless
you submit a form to that system using either POST or GET - in which
case, you get another page with additional forms etc...
now to answer your question.
see: <<
http://www.zend.com/zend/spotlight/shellscriptingp1.php
Example:
#!/usr/local/bin/php -q
<?php
function getInput($length=255)
{
$fr=fopen("php://stdin","r");
$input = fgets($fr,$length);
$input = rtrim($input);
fclose ($fr);
return $input;
}
echo "Enter some text (10 char max);
$text = getInput(10);
echo "you entered \n $text\n";
?>
Michael Austin.