Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn
Created June 26, 2012 08:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThijsFeryn/2994393 to your computer and use it in GitHub Desktop.
Save ThijsFeryn/2994393 to your computer and use it in GitHub Desktop.
Working with I/O streams in PHP
<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$stderr = fopen('php://stderr', 'w');
while(!feof($stdin)){
$line = trim(fgets($stdin));
if(strlen($line) > 0){
fwrite($stdout,strrev($line).PHP_EOL);
} else {
fwrite($stderr,"An empty line was passed".PHP_EOL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment