diff --git a/insert.php b/insert.php
index b163cae..60f9e65 100644
--- a/insert.php
+++ b/insert.php
@@ -1,17 +1,125 @@
$line) {
+// if($i == 100) exit();
+ if($skip != 0) {
+ $skip--;
+ continue;
+ }
+
+ if ($i == 3316) {
+ $break = true;
+ }
+ if (strpos(strtolower($line), '%') !== false) {
+ if (strpos(strtolower($line), 'ans ') !== false) {
+ preg_match_all('/\d+/', substr($line,1), $matches);
+ $questions[$x]['correctAnswer'] = $matches[0][0]; // <- this looks like eyes.
+ $x++; //NEXT QUESTION.
+ }
+ continue;
+ }
+ if (strpos(strtolower($line), '") continue;
+ } else {
+ $numbers = explode(" ", $line);
+ $questions[$x]['questionNumber'] = substr($numbers[0], 1);
+ }
+ $questionLine = $line;
+ $q=$i;
+ while(!empty($lines[$q+1])) {
+ if(strpos(strtolower($lines[$q+1]), 'Total questions:".$totalCount."
Good questions:".$goodCount."
Bad questions:".$badCount;
+exit();
+
+ //SECTIONS. Q/A/Q/A/Q/A
foreach ($data as $i => $d) {
if (empty($d)) continue;
if (strpos(strtolower($d), 'question') !== false) {
+ //PARSE THE QUESTION
$fullQuestion = substr(preg_replace('/^.+\n/', '', $d), 1); //Strip useless firstline.
$numbers = explode(" ", $fullQuestion);
$questions[$i]['questionNumber'] = $numbers[0]; // Get # of question
@@ -22,7 +130,7 @@ foreach($files as $file) {
preg_match('/".*?"/', $splitNewLine[0], $matches);
$questions[$i]['image'] = strtoupper($matches[0]);
- if (strpos($splitNewLine[1], ':') !== false && !empty(trim($splitNewLine[2]))) {
+ if (strpos($splitNewLine[1], ':') !== false || !empty(trim($splitNewLine[2]))) {
$twoLineQuestion = true;
}
$cutOutImageShit = explode(">", $splitNewLine[1]);
@@ -33,6 +141,8 @@ foreach($files as $file) {
} else {
if (strpos($splitNewLine[0], ':') !== false || !empty(trim($splitNewLine[1]))) {
if (strpos($splitNewLine[0], ':') !== false) {
+ if($questions[$i]['questionNumber'] == "10.2") error_log('here');
+
$twoLineQuestion = true;
if (strpos(strtolower($splitNewLine[1]), ' $line) {
//Don't ask what this witchcraft is. I don't know either.
- if ($a == 0) continue;
+ if ($a == 0 || $skip) {
+ $skip = false;
+ continue;
+ }
if (($twoLineQuestion || $imageFirstLine) && $a == 1) continue;
if ($threeLineQuestion || ($twoLineQuestion && $imageFirstLine) && $a == 2) continue;
if ($imageFirstLine && $threeLineQuestion && $a == 3) continue;
@@ -61,31 +176,53 @@ foreach($files as $file) {
$questions[$i]['image'] = strtoupper($matches[0]);
continue;
}
+
+// if(!empty($splitNewLine[$a+1])) {
+// if(!empty($splitNewLine[$a+2])) {
+// $questions[$i]['answers'][$b] = trim($line) . trim($splitNewLine[$a + 1]) . trim($splitNewLine[$a + 2]);
+// } else {
+// $questions[$i]['answers'][$b] = trim($line) . trim($splitNewLine[$a + 1]);
+// }
+// $skip = true;
+// } else {
+// $questions[$i]['answers'][$b] = trim($line);
+// }
+
$questions[$i]['answers'][$b] = trim($line);
+
$b++;
}
} elseif (strpos(strtolower($d), 'ans ') !== false) {
+ //PARSE THE CORRECT ANSWER
$questions[$i - 1]['correctAnswer'] = substr($d, 3);
}
}
-
- //CHECK ALL THE STUFF IS CORRECT.
- foreach($questions as $q) {
- $bad = false;
- if(count($q['answers']) != 4) $bad = true;
- if(!$q['correctAnswer']) $bad = true;
- if(!$q['questionNumber']) $bad = true;
- if(empty(trim($q['question']))) $bad = true;
- foreach($q['answers'] as $a) {
- if(empty(trim($a))) $bad = true;
- }
- if($bad) var_dump($q);
+//CHECK ALL THE STUFF IS CORRECT.
+foreach($questions as $q) {
+ $bad = false;
+ if(count($q['answers']) != 4) {
+ $bad = true;
}
+ if(!$q['correctAnswer']) $bad = true;
+ if(!$q['questionNumber']) $bad = true;
+ if(empty(trim($q['question']))) $bad = true;
+ foreach($q['answers'] as $a) {
+ if(empty(trim($a))) $bad = true;
+ }
+ if($bad) {
+ var_dump($q);
+ $badCount++;
+ } else {
+ $goodCount++;
+ }
+ $totalCount++;
+}
$questionArray = array_merge($questionArray, $questions);
-}
+
+echo "Array count:".count($questionArray)."
Total questions:".$totalCount."
Good questions:".$goodCount."
Bad questions:".$badCount;
exit();
$i = $b = $d = $a = $count = 0; //Clear the useless stuff from above.
foreach ($questionArray as $q) {
diff --git a/newinsert.php b/newinsert.php
deleted file mode 100644
index b003a7e..0000000
--- a/newinsert.php
+++ /dev/null
@@ -1,151 +0,0 @@
- $d) {
- if (empty($d)) continue;
- if (strpos(strtolower($d), 'question') !== false) {
- //PARSE THE QUESTION
- $fullQuestion = substr(preg_replace('/^.+\n/', '', $d), 1); //Strip useless firstline.
- $numbers = explode(" ", $fullQuestion);
- $questions[$i]['questionNumber'] = $numbers[0]; // Get # of question
- $lengthOfNumber = strlen($questions[$i]['questionNumber']); //Get length of #
- $splitNewLine = explode("\n", trim($fullQuestion)); //Split rest into lines.
- $twoLineQuestion = $imageFirstLine = $threeLineQuestion = false;
- if (strpos(strtolower($splitNewLine[0]), '", $splitNewLine[1]);
- $trashBin = array_shift($cutOutImageShit);
- $firstLine = implode(" ", $cutOutImageShit);
- $questions[$i]['question'] = trim(substr(($twoLineQuestion ? $firstLine . " "
- . $splitNewLine[2] : $firstLine), $lengthOfNumber));
- } else {
- if (strpos($splitNewLine[0], ':') !== false || !empty(trim($splitNewLine[1]))) {
- if (strpos($splitNewLine[0], ':') !== false) {
- if($questions[$i]['questionNumber'] == "10.2") error_log('here');
-
- $twoLineQuestion = true;
- if (strpos(strtolower($splitNewLine[1]), ' $line) {
- //Don't ask what this witchcraft is. I don't know either.
- if ($a == 0 || $skip) {
- $skip = false;
- continue;
- }
- if (($twoLineQuestion || $imageFirstLine) && $a == 1) continue;
- if ($threeLineQuestion || ($twoLineQuestion && $imageFirstLine) && $a == 2) continue;
- if ($imageFirstLine && $threeLineQuestion && $a == 3) continue;
- if (empty(trim($line))) continue;
- if (strpos(strtolower($line), 'totallines') !== false) continue;
-
- if (strpos(strtolower($line), 'Total questions:".$totalCount."
Good questions:".$goodCount."
Bad questions:".$badCount;
-exit();
-$i = $b = $d = $a = $count = 0; //Clear the useless stuff from above.
-foreach ($questionArray as $q) {
- $db = new db();
- $db->query("INSERT INTO question(question_time, questiondata_number, questiondata_content, questiondata_image)
- VALUES(:qTime, :qNumber, :qContent, :qImage)");
- $db->bind("qTime", time());
- $db->bind("qNumber", $q['questionNumber'] ?: 0);
- $db->bind("qContent", $q['question']);
- $db->bind("qImage", $q['image'] ?: "");
- $db->execute();
- $lastRow = $db->lastInsertId();
- $db->kill(); //IS THIS EVEN NEEDED?
- $row = 1;
- foreach ($q['answers'] as $a) {
- $db = new db();
- $db->query("INSERT INTO answer(answer_time, answerdata_content, answerdata_question, answerdata_correct)
- VALUES(:aTime, :aContent, :aQuestion, :aCorrect)");
- $db->bind("aTime", time());
- $db->bind("aContent", $a);
- $db->bind("aQuestion", $lastRow);
- $db->bind("aCorrect", ($q['correctAnswer'] == $row ? "1" : "0"));
- $db->execute();
- $db->kill();
- $row++;
- }
- $db = null;
- $count++;
-}
-echo "Inserted " . $count . " questions.";
\ No newline at end of file