Created
June 26, 2012 08:31
-
-
Save ThijsFeryn/2994393 to your computer and use it in GitHub Desktop.
Working with I/O streams in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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