Generation of footnote and endnote anchors and links

I have a number of documents with footnotes and endnotes in them. Some have as many as 35.
Each has a footnote and a corresponding endnote, numbered and in square brackets (e.g. [1]).
Is there any way of writing code that will generate an anchor and link for each footnote and a corresponding anchor and link for its endnote? Alternatively, can anyone suggest any existing software that will do it?
bogormanAsked:
Who is Participating?
 
ysreConnect With a Mentor Commented:
Hm on the existing software? Nopes.

On the textfile thing though:
Create a header containing the links eg. like this:
1<tab>http://www.link1.com/
2<tab>http://www.link2.com/foo.php/

etc.

Finish the table with something unique, eg:
ThisIsNoIdReally<tab>Foo bar Baz

Parse the textfile until this fake id "ThisIsNoIdReally", then get the rest of the file (ie. the text itself).
$content = "";
$links = array();

$endofheaderfound = false;

$fh = @fopen ($filename, "r");
while (!feof ($fh))
{
  $currline = @fgets ($fh, 8192);
  $foo = explode ("\t", $currline);
  if ($foo[0] == "ThisIsNoIdReally")
  {
    $endofheaderfound = true;
  }

  if ($endofheaderfound == false)
  {
    $links [$foo[0]] = $foo[1];
  }
  else    # grab the actual content aka real text
  {
    $content .= $currline;
  }
}
@fclose ($fh);

Parse the text and replace the footnotes, eg. [1] by <a href='$mylink1'>[1]</a>.

Or in programmer's speech ;), here PHP: $content = preg_replace ("/(\[$id\])/", "<a href='" .$links[$id]. "'">\[$id\]</a>", $content);

Repeat for every link you parsed in the beginning, eg.
sort($links); reset ($links);
while (list ($k, $v) = each ($links))
{
  $content = preg_replace ("/(\[$k\])/", "<a href='" .$links[$k]. "'">\[$k\]</a>", $content);
}

And finally add a list of endnotes below the real text:

sort($links); reset ($links);
while (list ($k, $v) = each ($links))
{
  $content .= "<a href='" .$links[$k]. "'">\[$k\]</a>\n";
}

And make the document a html document, eg.
$html_content = "<html>\n<body>\n" .$content. "</body>\n</html>\n";
$html_content = preg_replace ("/(\n)/", "<br>\n", $html_content);

And output the stuff:
print $html_content;


I just wrote this up without testing.. Should work with a text file based on the format defined at the top though :)

Ys
0
 
DenisvtCommented:
Just to be sure, can you confirm if those are web/server documents (ie PHP, HTML pages) or documents such as Word or of another type ?
0
 
bogormanAuthor Commented:
Hi Denisvt,
They would be either Word or text files with footnotes prefixed [1],[2]... and endnotes similarly prefixed
Regards
Brian
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
DenisvtCommented:
Ok this is out of my league then, I am more into PHP-related questions. Good luck.
0
 
bogormanAuthor Commented:
Hi Ys,
Thanks for all the work you have done on this. Am quite new to scripting but will follow your advice.
 Regards
Brian
0
 
ysreCommented:
Ok, you can ask me if you have additional questions, bogorman
0
All Courses

From novice to tech pro — start learning today.