From 58e0200fbdb5634becb4c777f9624998935a38ff Mon Sep 17 00:00:00 2001 From: Sven Ahrens Date: Wed, 2 Sep 2020 12:12:48 +0200 Subject: [PATCH] Get fallback value instead of taking the last element --- src/PhpWord/Reader/Word2007/AbstractPart.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 17dbceb4..2bc71b3a 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -293,14 +293,14 @@ abstract class AbstractPart } elseif ($node->nodeName == 'w:tab') { $parent->addText("\t"); } elseif ($node->nodeName == 'mc:AlternateContent') { - $hasChildren = $node->childNodes->length > 0; - - if ($hasChildren) { - $origin = $node->childNodes->item($node->childNodes->length - 1); + if ($node->hasChildNodes()) { + // Get fallback instead of mc:Choice to make sure it is compatible + $fallbackElements = $node->getElementsByTagName('Fallback'); - if ($origin->nodeValue) { + if ($fallbackElements->length) { + $fallback = $fallbackElements->item(0); // TextRun - $textContent = htmlspecialchars($origin->nodeValue, ENT_QUOTES, 'UTF-8'); + $textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8'); $parent->addText($textContent, $fontStyle, $paragraphStyle); }