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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Sat Jul 27 04:01:30 2024 UTC