|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
8 - 7 = ?
Subscribe to this entry?

 [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: Fri Apr 19 18:01:28 2024 UTC