php.net |  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:
MUST BE VALID
Solve the problem:
34 - 25 = ?
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")
      break;
  }

  fclose($fp);
}

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-09 23:18 UTC] jimw@php.net
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 Jul 26 23:01:30 2024 UTC