Forum


Replies: 3   Views: 4274
Problems with variable replacement
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 campagnuolo  · 17-11-2015 - 15:58

Hello,
I'm actually using phpdocx 4.1 (Corp. license) and I've got a strange problem while using importHeadersAndFooters.

What I'm doing is basically easy .... importing header and footer, reading the html response from a page that works with diffedent db data and create the final doc.

The import seems to work fine but I cannot replace the variable in the footer using the classic replaceVariableByText.

I've read on this forum that I cannot do this with newwordfrag.

I'll attach here my snippet. 
Just to let you know, this script will work without the "variable replacement" part.

I hope someone will be so kind to help me.

Best regards,
Frank

<?php
//phpdocx lib
require_once ("../phpdocx/classes/CreateDocx.inc");

$docx = new CreateDocx();

//the docx file with $VARIABLE$ in the footer
$docx->importHeadersAndFooters('footerheader.docx');

$variables = array('VARIABLE' => 'example');
$docx->replaceVariableByText($variables);

ob_start();
  include('print.php');
  $page = ob_get_contents();
ob_end_clean();

$docx->embedHTML($page , array('downloadImages' => true ));
ob_end_clean(); 

$docx->createDocxAndDownload('upload/test');

?>