PHP – read xml from zip/docx view well format


// read from zip/docx file

$_path     = 'my_report.docx';

$_xml    = 'word/document.xml'

if (true === $zip->open($_path)) {

if (($index = $zip->locateName($_xml)) !== false) {

$xml = $zip->getFromIndex($index);

$zip->close();

}
} else die('non zip file');

// well format it with domdocument class

$dom = new DOMDocument();

$dom->formatOutput = true;

$dom->preserveWhiteSpace = false;

$dom->loadXML($xml);

echo "<textarea style='width:100%; height: 520px;'>";
echo $dom->saveXML();
echo "</textarea>";

Published by

G3n1k

just to remember what i had known :)

One thought on “PHP – read xml from zip/docx view well format”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s