Skip to content

Instantly share code, notes, and snippets.

@moiaune
Created December 2, 2013 13:17
Show Gist options
  • Save moiaune/7749294 to your computer and use it in GitHub Desktop.
Save moiaune/7749294 to your computer and use it in GitHub Desktop.
Simple IO class for php CLI.
/*
* Description: Simple IO class for php CLI
* Author: Mads Aune
*/
if(!defined("STDIN")) { define('STDIN', fopen('php://stdin', 'r')); }
class CLI {
public static function getLine($prompt = '') {
echo $prompt . "> ";
return trim(fgets(STDIN));
}
public static function getInt($prompt = '') {
echo $prompt . "> ";
$input = (int) trim(fgets(STDIN));
return is_numeric($input) ? $input : false;
}
public static function say($text = '') {
echo $text;
}
public static function sayLine($text = '') {
echo $text . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment