-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
35 lines (26 loc) · 922 Bytes
/
run.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
$file = 'Uiljam_Golding_-_Poveliteljat_na_muhite_-1394-b.sfb';
$conv = new Sfblib\SfbToFb2Converter($file, dirname($file));
$conv->setObjectCount(1);
$conv->rmPattern(' —')->rmRegExpPattern('/^— /');
$conv->disableParagraphIds();
$conv->convert();
$testOutput = $conv->getContent();
// remove double new lines
$testOutput = preg_replace('/\n\n+/', "\n", $testOutput);
$testOutput = strtr($testOutput, [
"<p>\n" => '<p>',
"\n</p>" => '</p>',
]);
$testOutput = rtrim($testOutput, "\n");
// save output if wanted
$outDir = dirname($file) . '/output';
if (!file_exists($outDir)) {
mkdir($outDir, 0777, true);
}
file_put_contents($outDir .'/'. basename($file, '.sfb') . '.fb2', $testOutput);
echo 'converted, go to <strong>/output/<your-file-name>.fb2</strong>';