note 38022 added to ref.readline

From: Date: Fri, 05 Dec 2003 01:04:46 +0000
Subject: note 38022 added to ref.readline
Groups: php.notes 
Request: Send a blank email to php-notes+get-61427@lists.php.net to get a copy of this message
You can open /dev/tty on unix systems or \con in windows, with ob_implicit_flush(true) to write output unbuffered. Works like a charm :-) ------------------------------- #!/usr/local/bin/php -q <?php set_time_limit(0); @ob_end_flush(); ob_implicit_flush(true); class prompt { var $tty; function prompt() { if (substr(PHP_OS, 0, 3) == "WIN") { $this->tty = fOpen("\con", "rb"); } else { if (!($this->tty = fOpen("/dev/tty", "r"))) { $this->tty = fOpen("php://stdin", "r"); } } } function get($string, $length = 1024) { echo $string; $result = trim(fGets($this->tty, $length)); echo "\n"; return $result; } } echo "Enter something or 'exit' to quit\n"; do { $cmdline = new prompt(); $buffer = $cmdline->get("Something: "); echo "You said: $buffer\n"; } while ($buffer !== "exit"); echo "Goodbye\n"; ?> ---- Manual Page -- http://www.php.net/manual/en/ref.readline.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38022 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38022&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38022&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61427) next »