Page 1 of 1

Newbie question about PHP CLI and STDIN

Posted: Thu Aug 03, 2006 5:08 pm
by Chris Corbyn
How can a ask the user to enter a bit of text in STDIN but present them with a default value (for example, the one they last used) which they can either edit, backspace out or just use?

Hopefully this example will get over what I mean:

Code: Select all

<?php

echo "Enter something: ";

fwrite(STDIN, 'Foo');

$line = fgets(STDIN); //User sees "Enter something: Foo -- but godammit they can't backspace the word Foo out again"

echo "\n\n$line";

?>
I don't want to have to use readline or ncurses and I'm guessing it's not even needed.

Posted: Thu Aug 03, 2006 11:00 pm
by dull1554
never seen this used before.. are you making a console php app?

Posted: Thu Aug 03, 2006 11:10 pm
by Benjamin
Most linux applications do something like this..

Code: Select all

port (default 25):
Then if you press enter, without typing anything, it defaults to 25. Maybe you can do it like that?

Posted: Fri Aug 04, 2006 5:11 am
by Chris Corbyn
astions wrote:Most linux applications do something like this..

Code: Select all

port (default 25):
Then if you press enter, without typing anything, it defaults to 25. Maybe you can do it like that?
I thought of that but I wanted the user to be able to make minor edits to the previous text entered -- it's for naming stuff and the names vary only slightly.

I guess I'll use readline since I have PHP set up with it but I'll have to learn how to use it :( Fun fun fun :) Thanks guys.