diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 1ad901d480..777e7d189f 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -943,22 +943,11 @@ public function cloneBlock($blockname, $clones = 1, $replace = true, $indexVaria */ public function replaceBlock($blockname, $replacement): void { - $matches = []; - $escapedMacroOpeningChars = preg_quote(self::$macroOpeningChars); - $escapedMacroClosingChars = preg_quote(self::$macroClosingChars); - preg_match( - '/(<\?xml.*)(' . $escapedMacroOpeningChars . $blockname . $escapedMacroClosingChars . '<\/w:.*?p>)(.*)()/is', - $this->tempDocumentMainPart, - $matches + $this->tempDocumentMainPart = preg_replace( + '/(\${' . $blockname . '})(.*?)(\${\/' . $blockname . '})/is', + $replacement, + $this->tempDocumentMainPart ); - - if (isset($matches[3])) { - $this->tempDocumentMainPart = str_replace( - $matches[2] . $matches[3] . $matches[4], - $replacement, - $this->tempDocumentMainPart - ); - } } /**