From the course: PHP: Exporting Data to Files

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Outputting the database result as a .docx file

Outputting the database result as a .docx file - PHP Tutorial

From the course: PHP: Exporting Data to Files

Start my 1-month free trial

Outputting the database result as a .docx file

The way you generate a Microsoft word file from a database result, follows exactly the same pattern as we used in the previous chapter for an open document text file. The only difference is that we use the MS Word class instead of open doc. However, MS Word extends open doc. So, you need both the MS Word, and Open Doc class definitions in your site. We'll be using the XML class to convert the database results into XML. So, you need the XML class, and the base class, as well. Plus the autoloader. This is flowers_word.php, which we'll be using to generate the output file. The code at the top of the page, includes the auto loader, and then registers the foundation PHP namespace. Lines eight and nine import the XML, and MS Word classes, using the use operator. Line 11 includes the database result. I'm using the PDO version. If you are using MySQL change PDO to MySQLi. The code inside the tribe lock generates an XML string from the database result, the strip and split option removes html…

Contents