Skip to content

Instantly share code, notes, and snippets.

@tojibon
Created July 27, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tojibon/ea58d87b75b54413a2e7 to your computer and use it in GitHub Desktop.
Save tojibon/ea58d87b75b54413a2e7 to your computer and use it in GitHub Desktop.
Getting user data via Console Input with PHP.
<?php
function read ($length='255')
{
if (!isset ($GLOBALS['StdinPointer']))
{
$GLOBALS['StdinPointer'] = fopen ("php://stdin","r");
}
$line = fgets ($GLOBALS['StdinPointer'],$length);
return trim ($line);
}
echo "Enter your name: ";
$name = read ();
echo "\nHello $name! Where you came from? ";
$where = read ();
echo "\nI see. $where is very good place.";
//php php-console.php
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment