Replaces a group of variables within a set of table rows.

public replaceTableVariable (array $vars [, array $options])

This method is designed to generate a Word table with an, a priori, indetermined number of rows.

If one includes a set of placeholder variables in a set of rows phpdocx wil clone those rows the required number of times and populate the variables with the provided values.



This has to be an array of associative arrays. The keys of the associative array should match the names of the variables that you want to replace by their corresponding values (text strings or WordFragments).


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.
target string Possible values are: document (default), header, footer. This option sets the scope of the replacement procedure.
parseLineBreaks boolean If true (default is false) parses the line breaks to include them in the Word document.
type string inline (default) or block; used by WordFragment values.
addExtraSiblingNodes boolean If true (default is false) parses and adds nodes that don't have placeholders between placeholders.
Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like: