PHP 8.5.0 Alpha 2 available for testing

Voting

: max(eight, four)?
(Example: nine)

The Note You're Voting On

thflori
6 years ago
To read byte wise and multi line you can check the line_buffer from readline_info:

<?php

function read(int $count, string $prompt = null): string
{
$previous = '';
readline_callback_handler_install($prompt ?? " \e[D", function ($str) use (&$previous) {
$previous .= $str . PHP_EOL;
});
do {
$r = array(STDIN);
$n = stream_select($r, $w, $e, null);
if (
$n && in_array(STDIN, $r)) {
readline_callback_read_char();
$str = $previous . readline_info('line_buffer');
}
} while (
mb_strlen($str) < $count); // use strlen if you need the exact byte count
readline_callback_handler_remove();

return
$str;
}

<< Back to user notes page

To Top