S
S
sawa42016-05-30 14:12:33
PHP
sawa4, 2016-05-30 14:12:33

How to convert word to xml format using php?

it is necessary to enter the contents of a word document containing text, pictures into mysql tables. Estimated file structure
question text picture text
answer A) text
B) text
C) text
D) text
E) text
correct answer B
To do this, I want to convert to xml and manually import into MySQL

<database name="DB_NAME">
<!-- Таблица questions -->
<table name="questions">
  <column name="question_id">1</column>
  <column name="question">question 1</column>
  <column name="answer_a">answer_a 1</column>
  <column name="answer_b">answer_b 2</column>
  <column name="answer_c">answer_c 3</column>
  <column name="answer_d">answer_d 4</column>
  <column name="answer_e">answer_e 5</column>
  <column name="right_answer">right_answer 1</column>
</table>

or if you can automate, then immediately with worda in mysql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Misty Hedgehog, 2016-05-31
@paramtamtam

In theory, a docx format document is already an xml document, only compressed by the zip algorithm. All you need is:

$zip = new ZipArchive;
$doc_file = './publisher.docx';
$zip->open($doc_file);
$zip->extractTo('./tmp');

Then look at the content and use the simplexml_load_file function :
$xml = simplexml_load_file("./tmp/path_to.xml");
$xml->registerXPathNamespace('w',"http://schemas.openxmlformats.org/wordprocessingml/2006/main");
$text = $xml->xpath('//w:t');
echo '<pre>'; print_r($text); echo '</pre>';

stackoverflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question