readline_callback_handler_install
Description
The readline_callback_handler_install of Readline for PHP initializes the readline callback interface and terminal, prints the prompt and returns immediately.
Syntax
readline_callback_handler_install(
string $prompt,
callable $callback
): trueParameters
prompt
The prompt message.
callback
The callback function takes one parameter; the user input returned.
Return
Always returns true.
Examples
1 · prompt callback
<?
function myfunction($input)
{
echo $input;
}
$prompt = "myprompt";
$callback = "myfunction";
$return = readline_callback_handler_install($prompt, $callback);
var_export($return);
true
2
<?
function myfunction($input)
{
global $count, $prompting;
echo "You entered: $input\n";
if(10 < ++$count)
{
$prompting = false;
readline_callback_handler_remove();
}
else
{
$prompt = "myprompt";
$callback = "myfunction";
readline_callback_handler_install($prompt, $callback);
}
}
$count = 1;
$prompting = true;
$prompt = "myprompt";
$callback = "myfunction";
readline_callback_handler_install($prompt, $callback);
while($prompting)
{
$w = NULL;
$e = NULL;
$n = stream_select($r = array(STDIN), $w, $e, null);
if($n && in_array(STDIN, $r))
{
readline_callback_read_char();
}
}
echo "Prompting disabled. All done.\n";