Forum


Replies: 2   Views: 815
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 LucasSpl  · 08-03-2021 - 15:19

Hi,

i got the error

[08-Mar-2021 16:09:53 Europe/Paris] PHP Warning:  Undefined variable $descr in [...]/PhpDocx/classes/HTML2WordML.php on line 1455
[08-Mar-2021 16:09:53 Europe/Paris] PHP Warning:  Undefined variable $descr in [...]/PhpDocx/classes/HTML2WordML.php on line 1457

where i use

require_once(__DIR__ . '/PhpDocx/classes/CreateDocx.php');

$docx = new CreateDocx();
$docx->embedHTML($html);

$cheminDocx = DIR_TMP . getUniqId();
$docx->createDocx($cheminDocx);

 

$html got the value

<p><img src="data:image/png;base64,[...]" alt="" width="321" height="320" />texte</p>

if the link is not dead, you can check the base64 on https://textup.fr/534353xg (it's just a duck meme, any base64 img would have the error)
 

I'm using Premium 11

Regards.

 

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.

Posted by LucasSpl  · 08-03-2021 - 15:41

Working perfectly !

Thanks,

Regards