|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8515 Add function to read from stdin
Submitted: 2001-01-02 09:47 UTC Modified: 2002-02-09 23:18 UTC
From: ptuasca at hotmail dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4 OS: All
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ptuasca at hotmail dot com
New email:
PHP Version: OS:


 [2001-01-02 09:47 UTC] ptuasca at hotmail dot com
Hi folks.

Could you add a function to a next release that reads from stdin? It would make it easier to write console scripts...
A function with the same prototype of C scanf() would be great.

Also, a section in the manual regarding "How to use PHP to write shell/console scripts" would be nice (it took me a whole year to figure out that I could open stdin all the time...)

Currently, I use the following (do yo remember Pascal?):

Function Readln(&$INPUT){

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

  while (!feof($fp)) {

    $BUFFER = fgetc($fp);
    $INPUT .= $BUFFER;

    if ($BUFFER == "\n")


And by the way, keep up the good job with PHP! Congratulations!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-09 23:18 UTC]
you can just call fgets() or fscanf() on the file pointer from opening 'php://stdin'.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC