Forum


Replies: 1   Views: 159
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.

Posted by admin  · 22-12-2023 - 09:00

Hello,

Your username doesn't have any license tied. Please send to contact[at]phpdocx.com the username or email of the user that purchased the license you are using.

Regarding your question, we recommend you read the documentation available on https://www.phpdocx.com/documentation/practical/creating-a-new-document.

phpdocx includes an autoloader. When you require/include CreateDocx.php, all classes are available to be used. The phpdocx namespaces includes its own autoloader and can also be used with Composer to autoload classes.

Please note that this a PHP question. On https://www.php.net/manual/en/language.oop5.autoload.php you can read more information about how PHP autoloaders work.

Regards.