readline_callback_handler_install

Initializes the readline callback interface and terminal, prints the prompt and returns immediately

Syntax

readline_callback_handler_install(string $prompt, callable $callback): bool

Parameters

prompt

The prompt message.

callback

The callback function takes one parameter; the user input returned.

Return

Returns true on success or false on failure.

Examples

1

<?

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";

?>

			
		

readline

readline_add_history

readline_callback_handler_remove

readline_callback_read_char

readline_clear_history

readline_completion_function

readline_info

readline_list_history

readline_on_new_line

readline_read_history

readline_redisplay

readline_write_history

PHP

Home Menu