Home > Backend Development > PHP Tutorial > PHP generates a word document from a web page in the program and provides it for download_PHP tutorial

PHP generates a word document from a web page in the program and provides it for download_PHP tutorial

WBOY
Release: 2016-07-13 17:54:20
Original
1166 people have browsed it

In this article, we mainly solve two problems:
1: How to generate the content in html into a word document in php
2: When PHP generates the content in HTML into a word document, the display problem is not centered, that is, it will be displayed according to the web view by default.
3: When PHP generates content in HTML into a word document, there are related style incompatibility issues
Text:
echo '
                                                                                                                                                                                                     
;                           
                                                                                                     echo '


";
echo '
';
echo "Digital teaching system electronic lesson preparation manuscript

SubjectsChineseSchoolExperimental Middle School
';
                                                                                                                                                                                                                                ob_start(); //Open the buffer
header("Cache-Control: public");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
header('Content-Disposition: attachment; filename=test.doc');
}else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
Header('Content-Disposition: attachment; filename=test.doc');
} else {
header('Content-Disposition: attachment; filename=test.doc');
}
header("Pragma:no-cache");
header("Expires:0");
ob_end_flush();//Output all content to the browser
Note: The above code part provides the function of generating content in the PHP program file into the word document and providing the download function.
In response to the second question, after opening the word document downloaded locally, it will be displayed in the web view by default: as shown below:
Displayed according to the default web view:


If it is displayed according to the normal page view, you need to add a line of xml mark in the header for setting (blue code part): Print , the word document downloaded to the local after adding is displayed as shown below: PHP generates a word document from a web page in the program and provides it for download_PHP tutorial

Regarding the third problem, there are some style incompatibility issues, such as the underlined annotation of relevant attributes under the big title at the top:
We added the border-bottom: 1px solid #545454; style (blue code part) to the style in html, that is: , but underlined It is still not displayed because it is not recognized in Word. As shown below: PHP generates a word document from a web page in the program and provides it for download_PHP tutorial

The solution is to change it according to the subscript style recognized by word, that is: . After changing to this style, there will be underlines after the word document downloaded to the local is opened. The sign is displayed.
PHP generates a word document from a web page in the program and provides it for download_PHP tutorial
It is better to teach someone to fish than to teach him to fish. I will share with you my solution to this style incompatibility:
1: Find a web version of the online editor, then enter a few words in it, and then add an underline
2: Then click the View Source Code button on the editor. You can see that the underlined attribute just added is text-decoration: underline; instead of the style label in html: border-bottom: 1px solid #545454;
Okay, that’s it for the above related issues. If you have any questions, please ask them and we will discuss and solve them together.

points

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477948.htmlTechArticleIn this article, we mainly solve two problems: 1: How to generate the content in html to 2 in word document: When php generates the content in html into the word document, the display problem is not centered,...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template