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
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: 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")
      break;
  }

  fclose($fp);
}

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

Patches

Pull Requests

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 Oct 18 03:01:27 2024 UTC