readline()

readline() — Reads a line.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

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

Signature

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

Parameters

ParameterTypeWhat it takes
$prompt?stringYou may specify a string with which to prompt the user.

Return value

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.

Example

A runnable snippet:

//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());

All PHP 8.5 built-in functions

Reference card built from the PHP manual page readline() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.