note 101307 added to features.commandline.io-streams

From: Date: Thu, 09 Dec 2010 09:45:50 +0000
Subject: note 101307 added to features.commandline.io-streams
Groups: php.notes 
Request: Send a blank email to php-notes+get-174729@lists.php.net to get a copy of this message
Example: function ReadStdin($prompt, $valid_inputs, $default = '') { while(!isset($input) || (is_array($valid_inputs) && !in_array($input, $valid_inputs)) || ($valid_inputs == 'is_file' && !is_file($input))) { echo $prompt; $input = strtolower(trim(fgets(STDIN))); if(empty($input) && !empty($default)) { $input = $default; } } return $input; } // you can input <Enter> or 1, 2, 3 $choice = ReadStdin('Please choose your answer or press Enter to continue: ', array('', '1', '2', '3')); // check input is valid file name, use /var/path for input nothing $file = ReadStdin('Please input the file name(/var/path):', 'is_file', '/var/path'); you can add more functions if you want. ---- Server IP: 222.73.207.145 Probable Submitter: 127.0.0.1 (proxied: 210.22.77.166) ---- Manual Page -- http://www.php.net/manual/en/features.commandline.io-streams.php Edit -- https://master.php.net/note/edit/101307 Del: integrated -- https://master.php.net/note/delete/101307/integrated Del: useless -- https://master.php.net/note/delete/101307/useless Del: bad code -- https://master.php.net/note/delete/101307/bad+code Del: spam -- https://master.php.net/note/delete/101307/spam Del: non-english -- https://master.php.net/note/delete/101307/non-english Del: in docs -- https://master.php.net/note/delete/101307/in+docs Del: other reasons-- https://master.php.net/note/delete/101307 Reject -- https://master.php.net/note/reject/101307 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174729) next »