Re: PHP and the Console

From: Date: Mon, 20 Aug 2001 22:41:37 +0000
Subject: Re: PHP and the Console
Groups: php.general 
Request: Send a blank email to php-general+get-63602@lists.php.net to get a copy of this message
Here is a an extract from some code... Note that if you want to read more then one thing from the user, you better not close STDIN, cause you can only open it once. Here's the code it may not work without some fixing... dunno: -? php function Readln(&$INPUT){ // $fp = fopen("php://stdin","r"); while (!feof(STDIN)) { $BUFFER = fgetc(STDIN); $INPUT .= $BUFFER; if ($BUFFER == "\n") break; } // fclose($fp); } set_time_limit(0); ## Don't time out in interactive console mode. define ("STDIN", fopen("php://stdin","r")); ## Make STDIN a global thing. While (1) { $UserInput = preg_replace("/\n/","",$UserInput); $UserInput = preg_replace("/\r/","",$UserInput); switch (strtolower($UserInput)) { case "exit": case "quit": echo "goodbye!"; break 2; // exit switch and main loop /* do some other stuff ... */ } Readln($UserInput); } fclose (STDIN); ?- Northern.CA ===-- http://www.northern.ca Canada's Search Engine

« previous php.general (#63602) next »