Replaces a single variable within a list by a list of items.

public replaceListVariable (string $variable, array $listValues[, array $options])

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

If one includes the placeholder variable as a list item phpdocx will clone that entry the required number of times and populate the resulting items with the values provided by the $listValues array.



The name of the variable that you want to replace by a list of items.


The array with the values (text strings or WordFragments) you want to use to populate the list.


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.
Code samples

Example #1

The resulting Word document looks like: