diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 4e8f32e..a71db12 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.0050000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.0080000000000000002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.0030000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.031,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.012,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.0089999999999999993,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.025000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":2.1080000000000001}} \ No newline at end of file +{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.010999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.17499999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.0040000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.0030000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.23100000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.0060000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.042000000000000003,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":2.468}} \ No newline at end of file diff --git a/src/DocxDocument.php b/src/DocxDocument.php index 04a32e5..2bcda78 100644 --- a/src/DocxDocument.php +++ b/src/DocxDocument.php @@ -492,9 +492,10 @@ public function setImageValue($search, $replace): void $matches = array(); if (preg_match('/(<[^<]+>)([^<]*)(' . preg_quote($varNameWithArgsFixed) . ')([^>]*)(<[^>]+>)/Uu', $partContent, $matches)) { $wholeTag = $matches[0]; + $before = str_replace($varNameWithArgsFixed, '', $wholeTag); array_shift($matches); list($openTag, $prefix, , $postfix, $closeTag) = $matches; - $replaceXml = $openTag . $prefix . $closeTag . $xmlImage . $openTag . $postfix . $closeTag; + $replaceXml = $before . $openTag . $prefix . $closeTag . $xmlImage . $openTag . $postfix . $closeTag; // replace on each iteration, because in one tag we can have 2+ inline variables => before proceed next variable we need to change $partContent $partContent = $this->setValueForPart($wholeTag, $replaceXml, $partContent); } diff --git a/tests/templates/image.docx b/tests/templates/image.docx index c32c3ba..52ef0ad 100644 Binary files a/tests/templates/image.docx and b/tests/templates/image.docx differ