12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2013 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- *
- * How to read user input from the command line
- * useful for a cli script whoch needs user input
- * You need some input validation to make it "save"
- *
- * This Example reads user input until the user inputs a . at a single new line.
- * This .\n terminates the read process. The termination is not stored in the $input variable
- */
- $fp = fopen('php://stdin', 'r');
- $last_line = false;
- $input = '';
- while (!$last_line) {
- $next_line = fgets($fp, 1024); // read the special file to get the user input from keyboard
- if (".\n" == $next_line) {
- $last_line = true;
- } else {
- $input .= $next_line;
- }
- }
- ?>
|