'); require_once '../Classes/PHPWord.php'; $files = array( "Sample_01_SimpleText.docx", "Sample_02_TabStops.docx", "Sample_03_Sections.docx", "Sample_04_Textrun.docx", "Sample_05_Multicolumn.docx", "Sample_06_Footnote.docx", "Sample_07_TemplateCloneRow.docx", "Sample_08_ParagraphPagination.docx", "Sample_09_Tables.docx", ); foreach ($files as $file) { echo '
', date('H:i:s'), " Load from {$file} with contents:
"; unset($PHPWord); try { $PHPWord = PHPWord_IOFactory::load($file); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), '
'; continue; } $sections = $PHPWord->getSections(); $countSections = count($sections); $pSection = 0; if ($countSections > 0) { foreach ($sections as $section) { $pSection++; echo "Section {$pSection}:
"; $elements = $section->getElements(); foreach ($elements as $element) { if ($element instanceof PHPWord_Section_Text) { echo '' . htmlspecialchars($element->getText()) . '
'; } elseif ($element instanceof PHPWord_Section_TextRun) { $subelements = $element->getElements(); echo ''; if (count($subelements) > 0) { foreach ($subelements as $subelement) { if ($subelement instanceof PHPWord_Section_Text) { echo htmlspecialchars($subelement->getText()); } } } echo '
'; } elseif ($element instanceof PHPWord_Section_Link) { echo 'Link not yet supported.
'; } elseif ($element instanceof PHPWord_Section_Title) { echo 'Title not yet supported.
'; } elseif ($element instanceof PHPWord_Section_TextBreak) { echo 'Page break not yet supported.
'; } elseif ($element instanceof PHPWord_Section_Table) { echo 'Table not yet supported.
'; } elseif ($element instanceof PHPWord_Section_ListItem) { echo 'List item not yet supported.
'; } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage ) { echo 'Image not yet supported.
'; } elseif ($element instanceof PHPWord_TOC) { echo 'TOC not yet supported.
'; } elseif($element instanceof PHPWord_Section_Footnote) { echo 'Footnote not yet supported.
'; } } } } }