简体   繁体   中英

PHP-CLI How to write in user input?

I want to get predefined user input.

echo 'Enter value: ';
# here write some 'default value'
$value = fgets(STDIN);

So then user get prompt, he can edit input.

Enter value: default value # Here we can backslash and write new one.

How to achieve?

That is not the default/commen way of handling this stuff in shell scripts. In almost any programm you'll find something like this:

Enter your value: [Default Value]

$default = "Default Value";
echo "Enter your value: [", $default, "]";
$result = fgets(STDIN);
if (empty($result)) $result = $default;

Where as the default value gets set when the STDIN of that get was empty.

I'm pretty surr that the thing you want to achive isn't possible at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM