ask()
ask(string $question, string $default = '', \Closure|null $validator = null) : string
Ask a question, ask for results; return the result of the input
Parameters
string | $question | |
string | $default | |
\Closure|null | $validator | Validator, must return bool. |
Returns
stringExamples
is an example ```php $answer = Interact::ask('Please input your name?', null, function ($answer) { if (!preg_match('/\w{2,}/', $answer)) { // output error tips. Interact::error('The name must match "/\w{2,}/"'); return false; } return true; }); echo "Your input: $answer"; ``` ```php // use the second arg in the validator. $answer = Interact::ask('Please input your name?', null, function ($answer, &$err) { if (!preg_match('/\w{2,}/', $answer)) { // setting error message. $err = 'The name must match "/\w{2,}/"'; return false; } return true; }); echo "Your input: $answer"; ```
** File not found : This **