-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion.php
executable file
·40 lines (36 loc) · 1.15 KB
/
conversion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$input = file('./data.txt');
$output = fopen('./data.sql', 'w+');
$age = 1;
$year = 0;
$order = 1;
$count = 0;
echo 'Size of file: '.sizeof($input)."\n";
foreach ($input as $lineNumber => $line) {
if (strpos($line, "===") !== false && strpos($line, "===") == 0) {
$year = trim(substr($line, 3, 4));
$order = 1;
//echo 'Found year: '.$year."\n";
} else if (strpos($line, "=") !== false && strpos($line, "=") == 0) {
if (strpos($line, 'Colonization') !== false) {
$age = 1;
echo "Found: Age of Colonization\n";
} else if (strpos($line, 'War') !== false) {
$age = 2;
echo "Found: Age of War\n";
} else if (strpos($line, 'Betrayal') !== false) {
$age = 3;
echo "Found: Age of Betrayal\n";
}
} else if (strpos($line, "*") !== false && strpos($line, "*") == 0) {
$notes = trim(addslashes(substr($line, 1)));
$insertStatement = "INSERT INTO urswiki_timeline_events VALUES (0, '$year', '$year', '$age', $order, NULL, NULL, '$notes', NULL, NULL, NULL);\n";
fwrite($output, $insertStatement);
$order++;
$count++;
}
}
//echo 'Last Note: '.$notes."\n";
echo 'Counted '.$count.' number of timeline items.'."\n";
fclose($output);
?>