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 - PHP Tutorial
From the course: PHP: Exporting Data to Files
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Creating a .docx file to use as a template3m 37s
-
(Locked)
Extracting the main content file from a Word document5m 28s
-
(Locked)
Formatting the main content file3m 38s
-
(Locked)
Converting the main content file to XSLT6m 18s
-
(Locked)
Outputting the database result as a .docx file6m 4s
-
(Locked)
Offering a choice of download formats3m 55s
-
(Locked)
-