Skip to content

Commit 1cd4fbf

Browse files
author
Roman Syroeshko
committed
Performance improvement for #513.
1 parent 7fdc50b commit 1cd4fbf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ protected function fixBrokenMacros($documentPart)
356356
{
357357
$fixedDocumentPart = $documentPart;
358358

359-
$pattern = '|\$\{([^\}]+)\}|U';
360-
preg_match_all($pattern, $fixedDocumentPart, $matches);
361-
foreach ($matches[0] as $value) {
362-
$valueCleaned = preg_replace('/<[^>]+>/', '', $value);
363-
$valueCleaned = preg_replace('/<\/[^>]+>/', '', $valueCleaned);
364-
$fixedDocumentPart = str_replace($value, $valueCleaned, $fixedDocumentPart);
365-
}
359+
$fixedDocumentPart = preg_replace_callback(
360+
'|\$\{([^\}]+)\}|U',
361+
function ($match) {
362+
return strip_tags($match[0]);
363+
},
364+
$fixedDocumentPart
365+
);
366366

367367
return $fixedDocumentPart;
368368
}

0 commit comments

Comments
 (0)