Cookbook
- 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
Clean existing blocks
phpdocx includes several methods to work with block elements. These elements allow to define regions made of one or more contents in a DOCX, which can be cleaned of placeholders, deleted and cloned.
The deleteBlock method deletes block placeholders along with the whole of the region they enclose. This functionality allows to define optional regions in a DOCX template and decide whether or not to delete them dynamically.
E.g., the code that follows replaces an existing placeholder in a document, then erases the whole region delimited by $BLOCK_CHARTS$ placeholders and finally cleans the rest of the block placeholders:
Note that to call the deleteBlock method you have to write the placeholder identifier without neither the $BLOCK_ prefix (or any other custom block prefix using setTemplateBlockSymbol) nor the final $ symbol.