(PHP 5 >= 5.1.0, PHP 7)
readline_callback_handler_install — ��ʼ��һ�� readline �ص��ӿڣ�Ȼ���ն������ʾ��Ϣ����������
����һ�� readline �ص��ӿ�Ȼ����� prompt
����������.
�ڶ��ε��������������Ҫ�Ƴ���һ���ص��ӿڣ�����������Զ����ǾɵĽӿ�.
����� stream_select() ʱ�ص������Էdz����ã��������� IO ���û����� �佻����У�����readline().
prompt
��ʾ��Ϣ.
callback
callback
������Ҫһ������; �û����뽫������.
�ɹ�ʱ���� TRUE
�� ������ʧ��ʱ���� FALSE
��
Example #1 Readline Callback Interface Example
<?php
function rl_callback($ret)
{
global $c, $prompting;
echo "You entered: $ret\n";
$c++;
if ($c > 10) {
$prompting = false;
readline_callback_handler_remove();
} else {
readline_callback_handler_install("[$c] Enter something: ", 'rl_callback');
}
}
$c = 1;
$prompting = true;
readline_callback_handler_install("[$c] Enter something: ", 'rl_callback');
while ($prompting) {
$w = NULL;
$e = NULL;
$n = stream_select($r = array(STDIN), $w, $e, null);
if ($n && in_array(STDIN, $r)) {
// read a character, will call the callback when a newline is entered
readline_callback_read_char();
}
}
echo "Prompting disabled. All done.\n";
?>