Skip to content

Commit 58e0200

Browse files
committed
Get fallback value instead of taking the last element
1 parent 63d1ffc commit 58e0200

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@ protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, Abstrac
293293
} elseif ($node->nodeName == 'w:tab') {
294294
$parent->addText("\t");
295295
} elseif ($node->nodeName == 'mc:AlternateContent') {
296-
$hasChildren = $node->childNodes->length > 0;
297-
298-
if ($hasChildren) {
299-
$origin = $node->childNodes->item($node->childNodes->length - 1);
296+
if ($node->hasChildNodes()) {
297+
// Get fallback instead of mc:Choice to make sure it is compatible
298+
$fallbackElements = $node->getElementsByTagName('Fallback');
300299

301-
if ($origin->nodeValue) {
300+
if ($fallbackElements->length) {
301+
$fallback = $fallbackElements->item(0);
302302
// TextRun
303-
$textContent = htmlspecialchars($origin->nodeValue, ENT_QUOTES, 'UTF-8');
303+
$textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8');
304304

305305
$parent->addText($textContent, $fontStyle, $paragraphStyle);
306306
}

0 commit comments

Comments
 (0)