]> 91.132.146.200 Git - dolphin.git/commitdiff
methods and how to do.
authorBanana <johannes.kessler@bechtle.com>
Fri, 21 Jun 2013 06:31:50 +0000 (08:31 +0200)
committerBanana <johannes.kessler@bechtle.com>
Fri, 21 Jun 2013 06:31:50 +0000 (08:31 +0200)
methods-and-how-to/README [new file with mode: 0644]
methods-and-how-to/cli-user-input.php [new file with mode: 0644]

diff --git a/methods-and-how-to/README b/methods-and-how-to/README
new file mode 100644 (file)
index 0000000..1728deb
--- /dev/null
@@ -0,0 +1 @@
+Examples about how to do something.
\ No newline at end of file
diff --git a/methods-and-how-to/cli-user-input.php b/methods-and-how-to/cli-user-input.php
new file mode 100644 (file)
index 0000000..73aa0ae
--- /dev/null
@@ -0,0 +1,37 @@
+<?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;
+       }
+}
+
+?>
\ No newline at end of file