Akuba

Untitled

Oct 5th, 2013
256
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2.     ini_set('error_reporting', E_ALL);
  3.     $Question = array();
  4.     $DoneQuestion = array();
  5.     echo "Starte Quizkonverter.\n";
  6.     function startsWith($haystack, $needle)
  7.     {
  8.         return $needle === "" || strpos($haystack, $needle) === 0;
  9.     }
  10.     function endsWith($haystack, $needle)
  11.     {
  12.         return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
  13.     }
  14.     function isCompleteQuestion()
  15.     {
  16.         if($Question['Question'] != null && $Question['Answer'] != null && $Question['Question'] != "" && $Question['Answer'] != "") return true;
  17.         return false;
  18.     }
  19.     function QuestionExists($Question)
  20.     {
  21.         $i = 0;
  22.         while($i < count($DoneQuestion))
  23.         {
  24.             if($DoneQuestion[$i] == $Question) return true;
  25.         }
  26.         return false;
  27.     }
  28.     echo "Öffne Quizdatei und Destination Datei:\n";
  29.     $Quizfile=fopen("quiz.txt", "r");
  30.     $Destfile=fopen("quiz.sql", "c");
  31.     if($Quizfile && $Destfile)
  32.     {
  33.         $SQLSTART = "INSERT INTO `Quiz` (`Question`, `Answer`, `Regexp`, `Category`, `Level`) VALUES ";
  34.         fwrite($Destfile, );
  35.         while(($buffer = fgets($Quizfile, 4096)))
  36.         {
  37.             $line = trim($buffer);
  38.             if(startsWith($line, "#")) continue;
  39.             elseif(empty($line))
  40.             {
  41.                 if(isCompleteQuestion() && !QuestionExists($Question['Question']))
  42.                 {
  43.                     $String = ",\n('".$Question['Question']."', '".$Question['Answer']."', '".$Question['Regexp']."', '".$Question['Category']."', '".$Question['Level']."')"
  44.                     fwrite($Destfile, $String);
  45.                 }
  46.                 $Question['Question'] = "";
  47.                 $Question['Answer'] = "";
  48.                 $Question['Regexp'] = "";
  49.                 $Question['Category'] = "";
  50.                 $Question['Level'] = "";
  51.             }
  52.             elseif(startsWith($line, "Category:")) $Question['Category'] = trim(str_replace("Category:", "", $line));
  53.             elseif(startsWith($line, "Question:")) $Question['Question'] = trim(str_replace("Question:", "", $line));
  54.             elseif(startsWith($line, "Answer:")) $Question['Answer'] = trim(str_replace("Answer:", "", $line));
  55.             elseif(startsWith($line, "Regexp:")) $Question['Regexp'] = trim(str_replace("Regexp:", "", $line));
  56.             elseif(startsWith($line, "Level:")) $Question['Level'] = trim(str_replace("Level:", "", $line));
  57.         }
  58.     }
  59.     fclose($Quizfile);
  60.     fclose($Destfile);
  61.     echo "Fertig.";
  62. ?>
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment