replaceTableVariable
- addBibliography
- addBookmark
- addBreak
- addCaption
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addIndex
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addRuby
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableAuthorities
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- markEntry
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- importStylesWordDefault
- importTheme
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDecimalSymbol
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- removeTemplateVariableImage
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
replaceTableVariable

Replaces a group of variables within a set of table rows.
Description
public replaceTableVariable (array $vars [, array $options])
This method is intended to generate a Word table with an initially undetermined number of rows.
If a set of placeholder variables is included in a group of rows, phpdocx will clone those rows as many times as needed and populate the variables with the provided values.
Parameters
vars
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).
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. |
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. |
wordFragmentOptions (Available in Premium licenses) | array |
|
Code samples
Release notes
- phpdocx 17.0:
- wordFragmentOptions option.
- phpdocx 12.5:
- addExtraSiblingNodes option.
- phpdocx 7.0:
- header and footer targets.
- phpdocx 6.5:
- supported WordFragments as values.
- phpdocx 6.0:
- supported literals like '\n' and carriage returns like "\n" with the parseLineBreaks option.