From 1cd4fbf5aeb138fcff93bf456f2ecc9d7acbf8a2 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Tue, 2 Jun 2015 22:15:58 +0300 Subject: [PATCH] Performance improvement for #513. --- src/PhpWord/TemplateProcessor.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index e33ef682..827ece09 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -356,13 +356,13 @@ class TemplateProcessor { $fixedDocumentPart = $documentPart; - $pattern = '|\$\{([^\}]+)\}|U'; - preg_match_all($pattern, $fixedDocumentPart, $matches); - foreach ($matches[0] as $value) { - $valueCleaned = preg_replace('/<[^>]+>/', '', $value); - $valueCleaned = preg_replace('/<\/[^>]+>/', '', $valueCleaned); - $fixedDocumentPart = str_replace($value, $valueCleaned, $fixedDocumentPart); - } + $fixedDocumentPart = preg_replace_callback( + '|\$\{([^\}]+)\}|U', + function ($match) { + return strip_tags($match[0]); + }, + $fixedDocumentPart + ); return $fixedDocumentPart; }