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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
DenisvtCommented:
Ok this is out of my league then, I am more into PHP-related questions. Good luck.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ysreCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.