Skip to content

Commit

Permalink
change replaceblock to working workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
rhmck committed Feb 26, 2024
1 parent e76b701 commit d8b0b26
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/PhpWord/TemplateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.*)(<w:p.*>' . $escapedMacroOpeningChars . $blockname . $escapedMacroClosingChars . '<\/w:.*?p>)(.*)(<w:p.*' . $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
);
}
}

/**
Expand Down

0 comments on commit d8b0b26

Please sign in to comment.