Saturday, February 5, 2011

how can I read the contents of stdin (up until EOF) into a string in PHP?

how can I read the contents of stdin (up until EOF) into a string in PHP?

  • Use some of the file reading functions (e.g. fgets(), fgetc(), fscanf()) and pass in STDIN as the file path (or php://stdin, depending on how new your version of PHP is).

    You can test for the EOF using feof().

    See the reference for command-line programming in PHP on PHP.net for more information.

    From htw
  • ended up figuring it out myself:

    file_get_contents("php://stdin");
    
    From zak23

0 comments:

Post a Comment