Forum


Replies: 1   Views: 360
How to use replacevariablebytext
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 jonjie  · 22-12-2023 - 08:49

I am currently following the example here https://www.phpdocx.com/api-documentation/templates/replace-variable-text-Word-document, but the example is a bit confusing.

 

require_once 'classes/CreateDocx.php';

$docx = new CreateDocxFromTemplate('document.docx');

$first = 'PHPDocX';
$multiline = 'This is the first line.\nThis is the second line of text.';
$variables = array('FIRSTTEXT' => $first, 'MULTILINETEXT' => $multiline);

$options = array('parseLineBreaks' =>true);
$docx->replaceVariableByText($variables, $options);

$docx->createDocx('output');

 

1. As you can see the example above, it is using the CreateDocxFromTemplate class but then the imported class was CreateDocx.php.