Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit d8b0b26

Browse files
committed
change replaceblock to working workaround
1 parent e76b701 commit d8b0b26

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,22 +943,11 @@ public function cloneBlock($blockname, $clones = 1, $replace = true, $indexVaria
943943
*/
944944
public function replaceBlock($blockname, $replacement): void
945945
{
946-
$matches = [];
947-
$escapedMacroOpeningChars = preg_quote(self::$macroOpeningChars);
948-
$escapedMacroClosingChars = preg_quote(self::$macroClosingChars);
949-
preg_match(
950-
'/(<\?xml.*)(<w:p.*>' . $escapedMacroOpeningChars . $blockname . $escapedMacroClosingChars . '<\/w:.*?p>)(.*)(<w:p.*' . $escapedMacroOpeningChars . '\/' . $blockname . $escapedMacroClosingChars . '<\/w:.*?p>)/is',
951-
$this->tempDocumentMainPart,
952-
$matches
946+
$this->tempDocumentMainPart = preg_replace(
947+
'/(\${' . $blockname . '})(.*?)(\${\/' . $blockname . '})/is',
948+
$replacement,
949+
$this->tempDocumentMainPart
953950
);
954-
955-
if (isset($matches[3])) {
956-
$this->tempDocumentMainPart = str_replace(
957-
$matches[2] . $matches[3] . $matches[4],
958-
$replacement,
959-
$this->tempDocumentMainPart
960-
);
961-
}
962951
}
963952

964953
/**

0 commit comments

Comments
 (0)