Forum


Replies: 2   Views: 1583
Php warning: undefined variable $descr in html2wordml.php
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  · 08-03-2021 - 15:37

Hello,

Recent versions of PHP throws a Warning when trying to use a not initialized variable (previous PHP versions throw a Notice). Please apply the following change that is already included in the current testing version of phpdocx that will be included in the next release of phpdocx, that inits that $descr variable always to hide the warning when using a base64 image:

Edit HTML2WordML.php and after line 1291 in the classic package adds the following line:

$descr = 'image' . uniqid(mt_rand(999, 9999));

Instead of the following lines:

case 'img':
case 'svg':
  $this->wordML .= $this->closePreviousTags($depth, $nodo['nodeName']);
  if (isset($nodo['attributes']['src']) && strstr($nodo['attributes']['src'], 'base64,')) {

The code to be used after the previous change is the following:

case 'img':
case 'svg':
  $this->wordML .= $this->closePreviousTags($depth, $nodo['nodeName']);
  $descr = 'image' . uniqid(mt_rand(999, 9999));
  if (isset($nodo['attributes']['src']) && strstr($nodo['attributes']['src'], 'base64,')) {

This minor change should avoid that warning when using a base64 image and the newest versions of PHP.

Regards.