Forum


Replies: 2   Views: 275
Php warning when generating word file with loadhtml
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 jeroen8087  · 09-02-2022 - 08:18

Using PHPDocx 12.5, I get several PHP warnings and notices in my log file after creating a Word file. I use CreateDocxFromTemplate and replaceVariableByHTML, which produces the errors.

Depending on how many variables are replaced in the template, I get the following errors more than once, sometimes over 100 of them for one Word file:

Severity: Warning  --> DOMDocument::loadHTML(): Tag close invalid in Entity, line: 1 /Users/rolandvaandrager/Development/app/source/vendor/phpdocx/classes/DOMPDF_lib.php 2641
Severity: Notice  --> Undefined index: text_decoration /Users/rolandvaandrager/Development/app/source/vendor/phpdocx/classes/HTML2WordML.php 2493
Severity: Notice  --> Undefined offset: 5 /Users/rolandvaandrager/Development/app/source/vendor/phpdocx/classes/HTML2WordML.php 2019
Severity: Notice  --> Trying to access array offset on value of type null /Users/rolandvaandrager/Development/app/source/vendor/phpdocx/classes/HTML2WordML.php 2019

 

The first loadHTML() error is caused by a <close> tag in the HTML, which is generated by line 2705 in DOMPDF_lib.php:

$str = str_replace('</body>', '<close></body>', $str);

I don't know why this is done, it creates invalid HTML. If I remove this statement though, I get an invalid Word file with many more errors about unclosed tags in WordML.

 

The notices are caused by using the @ sign before an array, which is not accepted by PHP 7.4. Line 2493 of HTML2WordML.php states:

if (($this->openLinks && @$properties['text_decoration'] != 'none') || @$properties['text_decoration'] == 'underline') {

Here, $properties has no key 'text_decoration', and @ does not suppress the notice. I think that isset should be used here. These notices are also generated on other lines in this file, where the @ sign is used the same way.

 

What can be done to suppress these errors, other than just suppressing all PHP errors and warnings?