note 20906 added to ref.readline

From: Date: Sun, 21 Apr 2002 07:17:53 +0000
Subject: note 20906 added to ref.readline
Groups: php.notes 
Request: Send a blank email to php-notes+get-29630@lists.php.net to get a copy of this message
Here's an example simple readline-like way to input from command line on windows - the single line is from http://www.phpbuilder.com/columns/darrell20000319.php3, the multiline is something I added... <? function read () { # 4092 max on win32 fopen $fp=fopen("php://stdin", "r"); $in=fgets($fp,4094); fclose($fp); # strip newline (PHP_OS == "WINNT") ? ($read = str_replace("\r\n", "", $in)) : ($read = str_replace("\n", "", $in)); return $read; } function multilineread () { do { $in = read(); # test exit if ($in == ".") return $read; # concat input (PHP_OS == "WINNT") ? ($read = $read . ($read ? "\r\n" : "") . $in) : ($read = $read . "\n" . $in); } while ($inp != "."); return $read; } print("End input with . on line by itself.\n"); print("What is your first name?\n"); $first_name = multilineread(); print("What is your last name?\n"); $last_name = read(); print("\nHello, $first_name $last_name! Nice to meet you! \n"); ?> -- http://www.php.net/manual/en/ref.readline.php http://master.php.net/manage/user-notes.php?action=edit+20906 http://master.php.net/manage/user-notes.php?action=delete+20906 http://master.php.net/manage/user-notes.php?action=reject+20906

« previous php.notes (#29630) next »