Replies: 11   Views: 2058
Handling of lists..
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 admin  · 26-09-2019 - 10:21


The problem seems a Tidy problem that is adding extra tags (, although testing for example using PHP 7.3 no extra LI tag is added and the output is perfect.

Using a Premium license and HTML Extended it can be easily done:

$html = '
<ul class="textbox-list">
    <li>Have you heard of this animal before?</li>
    <phpdocx_break data-type="line" data-number="5" />
    <li>What do you already know about this animal?</li>
    <phpdocx_break data-type="line" data-number="5" />
$docx->embedHTML($html, array('useHTMLExtended' => true));

But as you are using an Advanced license, you could try updating to PHP 7.3 to check if the Tidy issue is solved automatically, or use an alternative approach compatible with all PHP versions:

$html = '
<ul class="textbox-list">
    <li>Have you heard of this animal before?$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$</li>
    <li>What do you already know about this animal?$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$</li>

$docxT = new Phpdocx\Create\CreateDocxFromTemplate('output_t.docx');
$wordFragment = new Phpdocx\Elements\WordFragment($docx);
$docxT->replaceVariableByWordFragment(array('VAR_BREAK' => $wordFragment), array('type' => 'inline'));

This code adds VAR_BREAK placeholders and then open the output as template to replace those placeholders by line breaks. You could also use DOCXPath [] to avoid generating a template and do all steps using only the CreateDocx class.