Replies: 5   Views: 2802
Html in table cell
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 developercoffeeshop  · 07-11-2018 - 13:37

How do I get HTML to format inside a table cell with addTable? I'll consider any method, even replacing HTML tags with wml

Posted by admin  · 07-11-2018 - 14:38


The addTable method, as other methods, allows adding WordFragments ( as contents.

You just need to create a new WordFragment, insert the HTML and then add the values to the table:

$html = new WordFragment($docx);

$valuesTable = array(
    'Title A',
    'Title B',
    'Title C',
   'Line A',
   'Line B',


You can see a full sample using WordFragments on the API page of the method (

You can also add a placeholder to the table as value an then use replaceVariableByHTML or replaceVariableByWordFragment to replace it with a WordFragment of the HTML.


Posted by developercoffeeshop  · 07-11-2018 - 17:17

Thanks, I understand how this would work, but since moving to the live server embedHTML no longer works, it actually gives an error 500 with nothing in the log. Any idea what could be causing this?

Posted by admin  · 07-11-2018 - 17:39


Maybe Tidy for PHP ( is not installed or enabled?

A 500 error is a generic PHP error and it should always being added to the log, we recommend to check your server configuration to find where are those errors added.

We also recommend you test the included samples (addText and embedHTML) using PHP CLI mode to check if the problem is from some missing PHP extension (ZIP, XML, Tidy), missing rw access, a license error or any other source.


Posted by developercoffeeshop  · 08-11-2018 - 06:40

Got it working by installing PHPtidy and validating the HTML, it seemed that & signs were causing some issues

$doc = new DOMDocument();
$data_text = str_replace(' ', ' ', $data_text);
$data_text = str_replace('&', '&', $data_text);

$html = new WordFragment($docx, 'document');


Posted by admin  · 08-11-2018 - 07:17


phpdocx handles all protected XML characters when adding new contents. Please check the exact content you are adding.