summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blaquiz.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/blaquiz.php b/blaquiz.php
new file mode 100644
index 0000000..d276e43
--- /dev/null
+++ b/blaquiz.php
@@ -0,0 +1,86 @@
+<?php
+ /*Bla Quiz - A Quiz program..*/
+
+ //Orginal Author: Phil Burton <philbeansburton@gmail.com>
+
+ // Version History
+ // 0.0.1 Created blaquiz.php
+
+ $version = "BlaQuiz Version: 0.0.1";
+
+ $questions = array (
+ "How many bits in a byte?",
+ "What does TTP mean?"
+ );
+ $answers = array (
+ "8",
+ "Time To Poo"
+ );
+ // get the input
+ $stdin = read_stdin();
+
+ $stdin = explode(" ", $stdin);
+ $out = "";
+ $token = "";
+ if(isset($stdin[0]))
+ {
+ switch ($stdin[0])
+ {
+ case "-q":
+ $id = rand(0,sizeof($questions) - 1);
+ $out = "ID: $id $questions[$id]";
+ break;
+ case "-a":
+ if(isset($stdin[1]) && isset($stdin[2]))
+ {
+ //Check question ID
+ $id = $stdin[1];
+ if($id < sizeof($questions))
+ {
+ //get answer
+ $answer = "";
+ for($i=2; $i<sizeof($stdin); $i++)
+ {
+ $answer .= $stdin[$i] . " ";
+ }
+ $answer = strtolower(substr($answer, 0 , -1));
+ if(strtolower($answers[$id]) == $answer)
+ {
+ $out = "Correct! $answer is the right answer!";
+ }
+ else
+ {
+ $out = "Nope, $answer is the wrong answer!";
+ }
+ }
+ else
+ {
+ $out = "Please give your answers like this: -a <answer>";
+ }
+ }
+ else
+ {
+ $out = "This question doesn't exist";
+ }
+ break;
+ default:
+ $out = "Please either ask for a new question: -q. Or guess at an answer -a <qid> <answer>.";
+ break;
+ }
+ }
+ else
+ {
+ $out = "Please either aska new question: -q or guess at an answer: -a <qid> <answer>.";
+ }
+ echo $out . "\n";
+
+
+ function read_stdin()
+ {
+ $fr=fopen("php://stdin","r"); // open our file pointer to read from stdin
+ $input = fgets($fr,128); // read a maximum of 128 characters
+ $input = rtrim($input); // trim any trailing spaces.
+ fclose ($fr); // close the file handle
+ return $input; // return the text entered
+ }
+?>