replaceVariableByExternalFile

replaceVariableByExternalFile

TRIAL / ADVANCED / PREMIUM

Replaces an array of variables by external files.

Description
public replaceVariableByExternalFile (array $variables[, array $options])

With the help of this method one may replace a single placeholder variable by a whole external document.

This method accepts the following document formats: DOCX, RTF, HTML and MHT.

Only compatible with MS Word 2007 or newer.

Parameters

variables

This is an array with the placeholder variables as keys and the path to the corresponding external document as value.

options

The possible keys and values of this array are:

Key Type Description
firstMatch boolean If the variable appears more than once within the Word document and firstMatch is set to true, phpdocx will only replace the first occurrence of the variable within the Word document.
matchSource boolean If true (default value) tries to preserve as much as possible the formatting of the inserted document.
Exceptions

File doesn't exist.

Invalid file extension.

Code samples

Example #1

The resulting Word document looks like: