php8.5
Home/ Manual/ readline / functions/ readline

readline

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Reads a line

Description

readline(string|null $prompt = null): string|false

Reads a single line from the user. You must add this line to the history yourself using readline_add_history().

Parameters

prompt

You may specify a string with which to prompt the user.

Return Values

Returns a single string from the user. The line returned has the ending newline removed. If there is no more data to read, then false is returned.

Examples

readline() Example

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

//dump history
print_r(readline_list_history());

//dump variables
print_r(readline_info());
?>

Source: reference/readline/functions/readline.xml · from the official PHP manual (php/doc-en)