Repository navigation
Expand file tree
/
Copy pathrunChapterSplicer.php
More file actions
73 lines (41 loc) · 1.58 KB
/
Copy pathrunChapterSplicer.php
File metadata and controls
73 lines (41 loc) · 1.58 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// =======================================================
// make edits
// the file that will be read from
$fileName = "textFile.txt";
// the chapter names to be searched for
$chptNames = ["Chapter 1", "Chapter 2", "Chapter 3", "Chapter 4", "Chapter 5"];
// you may also want to edit the target text file on line 29.
// end edits
// =======================================================
// the chapter splicer
include_once("ChapterSplicer.php");
// fn: write to console
function pen($words) { echo $words . "\n"; }
// the target text file
$dirName = dirname(__FILE__);
$txtFile = $dirName . "\\" . $fileName;
// --------------------------------------------------------------------
// intro
pen("Welcome to the chapter splicer.");
pen("Working with file \"" . $fileName . "\" ");
pen("and looking for " . count($chptNames) . " chapters" );
pen("");
// init the chapter splicer
$splicer = new ChapterSplicer($txtFile, $chptNames);
// if (!$splicer) echo "splicer not created\n"; else echo "yes on splicer\n";
// search the file text for the chapter names
$splicer->hasChapters();
$splicer->seeChapterResults();
$splicer->makeChapterSubstrings();
// make chapter files from substrings collected
$targetFolder = $dirName . "\\" . "target";
$targetFileNames = [];
for ($i = 0; $i < count($chptNames); $i++)
{
// the name of the file that will be created
$targetFileNames[$i] = $targetFolder . "\\" . "chapter" . ($i + 1) . ".txt";
}
// make chapter files
$splicer->makeChapterFiles($targetFileNames);
?>