Forum


Replies: 2   Views: 2507
Catch replacevariablebytext internal warning when variable does not exists
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  · 13-10-2017 - 08:14

Hello,

The warning you point out is thrown by PHP; some functions of PHP throw exceptions and others throw notice/warning/fatal messages that can't be catched using a try-catch block (https://stackoverflow.com/questions/7082401/avoid-domdocument-xml-warnings-in-php). If needed, you can register a custom error handler to get that messages and throw exceptions (https://stackoverflow.com/questions/1759069/php-domdocument-error-handling).

Anyway, phpdocx ignores placeholders that don't exist. You could get the placeholders from a template using the getTemplateVariables (https://www.phpdocx.com/api-documentation/templates/get-Word-template-variables) and compare the array this method returns to know if a placeholder exists, and then replace it or not.

But we think there must be an error on the template you are using. If you send to contact[at]phpdocx.com the most simple script and template that illustrates your issue the dev team will check it. The dev team needs to run it, so please avoid external connections, and send the smallest code to be able to test it.

Regards.