php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14003 fgetc from php://stdin doesn't return after one byte typed
Submitted: 2001-11-09 20:09 UTC Modified: 2002-07-24 16:57 UTC
Votes:27
Avg. Score:4.5 ± 1.0
Reproduced:21 of 23 (91.3%)
Same Version:5 (23.8%)
Same OS:4 (19.0%)
From: llam at alumni dot uwaterloo dot ca Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.0.6 OS: Linux 2.4.17
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: llam at alumni dot uwaterloo dot ca
New email:
PHP Version: OS:

 

 [2001-11-09 20:09 UTC] llam at alumni dot uwaterloo dot ca
<?

$rtdin = fopen("php://stdin", "r");

for(;;){
        $c = fgetc($rtdin);
        fflush($rtdin);
        if ($c == 'q') break;
        else echo "you pressed:" . $c . "\n";
}

?>

=========
This script doesn't work as expected: fgetc doesn't return until "\n" is read from stdin.

How can I catch single key-presses from the keyboard?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-24 16:57 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is a normal behavour, if you try simular code in C you will get the same results.
Consider using ncurses.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 06:01:29 2025 UTC