diff --git a/.gitignore b/.gitignore
index f3adafd..a091a5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.DS_Store
/data/
+OUTPUT/*
\ No newline at end of file
diff --git a/README.md b/README.md
index bb62c35..b100245 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,19 @@ HtmlQ introduces a few new settings that were not available in FlashQ:
- Your answers will be lost.
```
+### CSV Export
+
+If your webspace supports [PHP](https://www.php.net/) then you can config HtmlQ to write all results into a CSV file. You will find the CSV file in the folder with the name `OUTPUT`. Delete the file to start a new survey.
+
+`settings/config.xml`:
+
+```xml
+
+ - src/save_as_csv.php
+
+ - get
+```
+
## Creating unique participation links (UID)
If you want to send out unique links to a HtmlQ survey that will automatically fill in the UID/user code, you can create links in the following format: [https://www.yourdomain.com/htmlq/#/?userCode=USERCODE](). In the resulting CSV file, the user code will show up in the UID field. This allows you to identify participants without requiring them to log in.
diff --git a/src/save_as_csv.php b/src/save_as_csv.php
new file mode 100755
index 0000000..974e5ea
--- /dev/null
+++ b/src/save_as_csv.php
@@ -0,0 +1,90 @@
+
+ * - src/save_as_csv.php
+ *
+ * - get
+ *
+ * You will find the generate CSV file in the folder OUTPUT. Simply move or delete the file if you
+ * would like to start a new survey.
+ *
+ * @author Paul Spiesberger - no warrenty for any dataloss or other harm.
+ */
+
+$filePath = "../OUTPUT/survey_results.csv";
+
+createDir("../OUTPUT/"); // create directory if it doesn't exist yet
+
+$csvFile = fopen($filePath, "a") or die("Unable to open file!");
+
+// Extract comments
+$comments = array();
+$commentHeaders = array();
+
+for ($x = 0; $x <= 10000; $x++) {
+ $key = "comment" . $x;
+
+ if(isset($_GET[$key])) {
+ $comments[] = htmlspecialchars($_GET[$key]);
+ $commentHeaders[] = "comment" . sizeof($commentHeaders);
+ }
+}
+
+// Extract Forms
+$forms = array();
+$formHeaders = array();
+
+for ($x = 0; $x <= 10000; $x++) {
+ $key = "form" . $x;
+
+ if(isset($_GET[$key])) {
+ $forms[] = htmlspecialchars($_GET[$key]);
+ $formHeaders[] = $key;
+ }
+}
+
+// Extract Durations
+$durations = array();
+$durationHeaders = array();
+
+for ($x = 0; $x <= 10000; $x++) {
+ $key = "dur" . $x;
+
+ if(isset($_GET[$key])) {
+ $durations[] = htmlspecialchars($_GET[$key]);
+ $durationHeaders[] = $key;
+ }
+}
+
+// Adding headers
+if (filesize($filePath) == 0) {
+
+ $headers = array("uuid", "name", "datetime", "nneg", "nneu", "npos", "sort");
+ $headers = array_merge($headers, $commentHeaders, $formHeaders, $durationHeaders);
+ fputcsv($csvFile, $headers);
+}
+
+// Create Data Arrays
+$data = array_merge(array(
+ uniqid(), // generate random UUID
+ htmlspecialchars($_GET["name"]),
+ htmlspecialchars($_GET["datetime"]),
+ htmlspecialchars($_GET["nneg"]),
+ htmlspecialchars($_GET["nneu"]),
+ htmlspecialchars($_GET["npos"]),
+ htmlspecialchars($_GET["sort"])
+), $comments, $forms, $durations);
+
+fputcsv($csvFile, $data); // Write data
+
+fclose($csvFile); // Closing file
+
+function createDir($path, $mode = 0777, $recursive = true) {
+ if(file_exists($path)) return true;
+ return mkdir($path, $mode, $recursive);
+}
+?>
\ No newline at end of file