Snippets
- Learn phpdocx in 5 minutes
- Tutorial
- API quick guide
- HTML to Word
- HTML Extended
- Conversion plugin
- Word to HTML
- DOCXPath
- Bulk processing
- DOCXCustomizer
- Digital signature
- Cryptophpdocx
- Right to left languages
- phpdocx CLI command
- Tracking
- Artificial Intelligence
- Blockchain for documents
- JavaScript API
- Compiled mode
Replace placeholders with the same name by unique values
Placeholder replacement methods such as replaceVariableByText substitute all placeholders in a document with a new value. If a document contains a repeated placeholder that you don't want to replace with the same value, the firstMatch parameter allows to replace only the first result. This way, each time it is called, the next placeholder is replaced with a unique value.
The following code replaces all PLACEHOLDER variables with data of the $values array, substituting only the first match of the variable on every iteration:
Compatible methods with this parameter are: