Thank you very much.
I just sent you a Private Message with the link to the file and the names.
I am really excited about the idea of php to skip the manual copy and paste work!
Hi Clemens,
I'll put the code online so it may be usefull to others (and mayby someone can improve on it or find an indesign-solution)
You'll have to
- create a folder in htdocs
- add a folder named "input" and one named "output".
- Put your html-files in the input folder.
- Put this code in a file in the root of the folder that contains both directories.
- Run it in your browser.
- Done... You'll find your changed files in the output-folder - they will show up as links so you can check them at once
Take care: if you recompress the files to zip and change back to epub the mimetype file must be added to the archive first and without compression - the other files can then be added with highest compression.
<?php
$filenames = array();
//loop through input directory and put all files in an array
if ($handle = opendir('./input')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$filenames[]=$entry;
}
}
closedir($handle);
}
//fill variable with contents of each file, one file at a time
$tekst ="";
foreach($filenames as $key => $filename){
$startfile = "./input/".$filename;
if (file_exists($startfile)) {
$fo = fopen($startfile, "r");
while ( $line = fgets($fo) ) {
$tekst .= $line;
}
//link endnote references in 2 directions
//protect class in endnote-text --> not necessary if class of numbers in endnote-text is different from class of numbers in text
$tekst = str_replace('<p class="Testo-note"><span class="Super">','<p class="Testo-note"><span class="##Super">',$tekst);
//put anchors before endnote-numbers and link to endnote-text
$tekst = preg_replace('/(<span class="Super">)(\\d+)/', '<a id="notenumber$2"></a>$1<a href="#notetext$2">$2</a>', $tekst);
//reverse protection --> not necessary if class of numbers in endnote-text is different from class of numbers in text
$tekst = str_replace('<p class="Testo-note"><span class="##Super">','<p class="Testo-note"><span class="Super">',$tekst);
//put anchors before endnote-text and link to endnote-numbers
$tekst = preg_replace('/(<p class="Testo-note"><span class="Super">)(\\d+)/', '<a id="notetext$2"></a>$1<a href="#notenumber$2">$2</a>', $tekst);
//change inputfolder to outputfolder and write changed file to outputfolder
$endfile = str_replace("input","output",$startfile);
$fo = fopen($endfile, "w");
fwrite($fo,$tekst);
$tekst ="";
}
}
//display changed files as link
if ($handle = opendir('./output')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<br /><a href='./output/".$entry."'>".$entry."</a>";
}
}
closedir($handle);
}
?>