Created
January 18, 2012 23:58
-
-
Save aknosis/1636629 to your computer and use it in GitHub Desktop.
Read from stdin to a php variable
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 | |
/** | |
* Usage: | |
* $answer = prompt("What is your quest?"); | |
* echo "Answer: $answer"; | |
* | |
* Outputs: | |
* What is your quest? | |
* I seek the holy grail! | |
* Answer: I seek the holy grail! | |
*/ | |
function prompt($msg){ | |
echo "$msg\n"; | |
return trim(fgets(STDIN)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment