Forum


Replies: 10   Views: 4211
Footnotes and embedhtml()
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by shroom  · 21-12-2015 - 18:46

I think this is my last major issue.  I would like to know how to deal with footnotes in text that contains HTML.  I can create footnotes in plain text, but need some direction on how to deal with footnotes in HTML:

$thetext    = 'The quick <em>brown fox</em>[fn] jumped over the lazy <strong>sleeping dog</strong>.[fn]  And the story continues...';
$footnotes  = 'footnote for the italicized brown fox~~footnote for the bolded sleeping dog~~';

How would I process this to render BOTH the HTML and link the footnotes?  The [fn] markers indicate what the footnotes are attached to.  IE: the first [fn] marker references "footnote for the italicized brown fox" and the second marker references "footnote for the bolded sleeping dog".  Using addText(), I can properly attach the footnotes, but the HTML is not rendered.  It comes out like this:

The quick <em>brown fox</em>1 jumped over the lazy <strong>sleeping dog</strong>.2  And the story continues...

(at bottom of page..)
--------------------------------------
1 footnote for the italicised brown fox
2 footnote for the bolded sleeping dog

(Note that in the Word doc, the "1" and "2" are properly superscripted, but this editor does not show that)

So again, how would I process this to render BOTH the HTML and link the footnotes?  I would greatly appreciate it if you can point me in the right direction.

Posted by shroom  · 21-12-2015 - 18:59

This is what I have so far, and it works as far as linking the footnotes, but how should I process the HTML?

.............
$docx = new CreateDocx();

$mytext     = 'The quick <em>brown fox</em>[fn] jumped over the lazy <strong>sleeping dog</strong>.[fn]  And the story continues...';
$footnotes  = 'footnote for the italicized brown fox~~footnote for the bolded sleeping dog~~';

$artext = explode('[fn]', $mytext);
$arfoot = explode('~~', $footnotes);

$text = array();

for ($ni=0;$ni<sizeof($artext);$ni++) {
    if($arfoot[$ni]!=''){
        $tmp = new WordFragment($docx, 'document');
        $tmp->addFootnote(
            array(
                'textDocument' => $artext[$ni],
                'textFootnote' => $arfoot[$ni],
            )
        );
    }else{
        $tmp = array('text' => $artext[$ni]);
    }
                $text[] = $tmp;
}

$docx->addText($text);

$docx->createDocxAndDownload('mySample');

Thanks.

Posted by shroom  · 22-12-2015 - 11:20

>>It adds HTML to a footnote.

I'm sorry if I was not clear.

The examples for addFootnote() do not cover what I need to do.  I do not want to add HTML to the footnote.  I want to put footnotes in text that contains HTML.  What I asked above covers what I need to do.

Thanks.

Posted by admin  · 22-12-2015 - 11:25

Hello,

The ways to add footnotes are the explained on that page, there's no more solutions.

Regards.

Posted by shroom  · 22-12-2015 - 11:30

>>The ways to add footnotes are the explained on that page, there's no more solutions.

I know how to add footnotes.  What I am trying to do is add footnotes to text that contains HTML.  Neither of the examples for adding footnotes demonstrate what I need to do.  

Are you saying it's not possible to insert footnotes into text that contains HTML?

Thanks

Posted by admin  · 22-12-2015 - 11:37

Hello,

You'd need to create the document where HTML has placeholders and then open it as a template to replace that placeholders by WordFragments.

You can't do it in one step.

Regards.

Posted by shroom  · 22-12-2015 - 11:54

The entire documents we need to create are text that contains HTML.  There is no way that I know of to create a template with placeholders to plug in bits of HTML or bits of text with footnotes.  The template would contain one placeholder...  We are essentially pulling text containing HTML from the database and "streaming" it to phpdocx using embedHTML().

I understand I may not be able to use embedHTML() any more, which is too bad, because it generally works very well, and is the main reason we purchased phpdocx.  But I need some way to get footnotes into text that contains HTML.  Surely there is SOME way to do it...

Thanks

Posted by admin  · 22-12-2015 - 11:58

Hello,

As explained previously, there's NO other way to do it. Of course you can change the library, as it's open source (not free source), but you need to do it on your own.

Regards.

Posted by shroom  · 22-12-2015 - 15:12

Thanks.

In other words, it is currently not possible to insert footnotes into text that contains HTML.  My choices are to either manually parse the text looking for HTML tags, and assemble the docx using addText(), which does support footnotes, or use embedHTML() and forego footnotes. 

I have a suggestion for phpdocx.  Have embedHTML() support a pseudo HTML tag <footnote>:

$thetext = 'The quick <em>brown fox</em><footnote>this is a footnote for the brown fox</footnote> jumped over the lazy <strong>sleeping dog</strong>.<footnote>this is a footnote for the sleeping dog</footnote> And the story continues...';

$docx -> embedHTML($thetext);

EmbedHTML() could then process the <footnote> tag, inserting the proper WordML to have what's contained between the <footnote> tags become Word footnotes.

That's what I'm going to try and do.  Wish me luck.

 

Posted by shroom  · 23-12-2015 - 14:22

>>I have a suggestion for phpdocx.  Have embedHTML() support a pseudo HTML tag <footnote>.

It took me most of the day yesterday, but I did this ^^, and it works great!