Replaces placeholder variables by text.

public replaceVariableByText (array $variables[, array $options])

This method is designed to replace a set of placeholder variables by plain text.

Remember that the phpdocx template variables should be surrounded by $ symbols or whatever symbol you have chosen via the setTemplateSymbol method.



This must be an array with the names of the placeholder template variables as keys and the plain text that should replace them as values.


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 ocurrence of the variable within the Word document.
parseLineBreaks boolean If true (default is false) parses the line breaks to include them in the Word document.
target string Possible values are: document (default), header, footer, footnote, endnote, comment. This option sets the scope of the replacement procedure.
raw boolean if true (default is false) replaces the variable by a string regardless the variable scope (tag values, attributes...). Only allows to replace a variable by a plain string. Use with caution.
Return values


Code samples

Example #1

The resulting Word document looks like: