PHP readline_info Function – Get and Set Readline Variables

The PHP readline_info function retrieves or sets internal readline variables, returning all settings as an array when called without arguments or the previous value when a variable name (and optional new value) is provided, with usage illustrated by a complete code example.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP readline_info Function – Get and Set Readline Variables

The readline_info function in PHP allows you to retrieve or set internal readline variables.

When called without arguments, it returns an associative array containing all current readline settings such as done, end, prompt, and others. If one or two arguments are provided, the function sets the specified variable and returns its previous value.

Parameters: varname (string) – the name of the variable to get or set. newvalue (string, optional) – the value to assign to the variable.

Return value:

Without parameters: an array of all readline settings.

With parameters: the original value of the specified variable.

Example usage:

<?php
// get 3 commands from user
for ($i = 0; $i < 3; $i++) {
    $line = readline("Command: ");
    readline_add_history($line);
}
print_r(readline_list_history());
print_r(readline_info());
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIreadline
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.