seld/cli-prompt
Cross-platform CLI user input prompts for PHP. Read normal input or securely prompt for passwords/secret values with hidden typing. Automatically trims the trailing newline; optional visible fallback if hidden input isn’t available. Composer install.
While prompting for user input using fgets() is quite easy, sometimes you
need to prompt for sensitive information. In these cases, the characters typed
in by the user should not be directly visible, and this is quite a pain to
do in a cross-platform way.
This tiny package fixes just that for you:
<?php
echo 'Say hello: ';
$answer = Seld\CliPrompt\CliPrompt::hiddenPrompt();
echo 'You answered: '.$answer . PHP_EOL;
// Output in the CLI:
//
// Say hello:
// You answered: hello
composer require seld/cli-prompt
Seld\CliPrompt\CliPrompt::hiddenPrompt($allowFallback = false);
Prompts the user for input and hides what they type. If this fails for any reason and
$allowFallbackis set totruethe prompt will be done using the usualfgets()and characters will be visible.
Seld\CliPrompt\CliPrompt::prompt();
Regular user prompt for input with characters being shown on screen.
In both cases, the trailing newline the user enters when submitting the answer is trimmed.
PHP 5.3 and above
CLI-Prompt is licensed under the MIT License - see the LICENSE file for details
How can I help you explore Laravel packages today?