-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_vl.php
65 lines (61 loc) · 1 KB
/
extract_vl.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
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
<?php
/**
* extract_vl.php
*
* Simple script which extracts dialogue lines for given
* character within a fountain document.
*
* For example: I run "php extract_vl.php screenplay.fountain BOB"
*
* While the content of "screenplay.fountain" is:
*
* Bob went outside.
*
* BOB
* I love birds!
*
* Richard came by.
*
* RICHARD
* Me too!
*
* BOB
* You're weird, Richard.
*
* The output of this script will be:
*
* I love birds!
*
* You're weird, Richard.
*/
$file = file_get_contents($_SERVER['argv'][1]);
$target = strtoupper($_SERVER['argv'][2]);
$output = [];
$grab_next = false;
$lines = explode("\n", $file);
foreach ($lines as $line)
{
if ($grab_next)
{
if (empty(trim($line)))
{
$grab_next = false;
}
else
{
$output[] = $line;
}
}
else if (strpos($line, $target) !== false)
{
$grab_next = true;
}
}
if (empty($output))
{
echo "Found nothing for '$target'...";
}
else
{
echo implode("\n\n", $output);
}