Home  >  Article  >  Backend Development  >  PHP web page saved as Word document

PHP web page saved as Word document

WBOY
WBOYOriginal
2016-07-29 08:57:091105browse

The following is a step-by-step explanation of how to convert the news code part in the web page into a Word document

1. Specify the Microsoft Word namespace

<code>echo '<span><<span>html</span><span>xmlns:o</span>=<span>"urn:schemas-microsoft-com:office:office"</span><span>xmlns:w</span>=<span>"urn:schemas-microsoft-com:office:word"</span><span>xmlns</span>=<span>"http://www.w3.org/TR/REC-html40"</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>http-equiv</span>=<span>"Content-Type"</span><span>content</span>=<span>"text/html; charset=utf-8"</span>/></span><span></<span>head</span>></span>';</code>

2. Output the actual HTML content

<code><span>echo</span><span>$html</span>;</code>

3. Set the header

<code><span>header(<span>"Cache-Control: public"</span>)</span>; 
<span>Header(<span>"Content-type: application/octet-stream"</span>)</span>; 
<span>Header(<span>"Accept-Ranges: bytes"</span>)</span>; 
<span>header(<span>'Content-Disposition: attachment; filename=test.doc'</span>)</span>; 
<span>header(<span>"Pragma:no-cache"</span>)</span>; 
<span>header(<span>"Expires:0"</span>)</span>; </code>

The complete code is as follows :

<code><?php
echo <span>'<span><html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:w="urn:schemas-microsoft-com:office:word"
    xmlns="http://www.w3.org/TR/REC-html40">
    <head><meta http-equiv=<span>"Content-Type"</span> c>"text/html; charset=utf-8"</span>/></head><span>';</span>$html = <span>'<span><p></span><span><span></span><span><strong></span><span><span></span>来源:四川网  2014年4月23日<span></span></span><span></strong></span><span></span></span><span></p></span><span><p></span><span><span></span>日前,全国高校校园文化建设工作推进现场会在西南民族大学举行。教育部思政司司长冯刚、四川省教育厅厅长朱世宏、四川省委教育工委委员李光华出席会议。教育部、四川省教育厅以及全国近百所高校的专家学者、思政宣传工作负责人出席会议。与会代表就如何推进高校校园文化建设、让高校师生将社会主义核心价值观“内化于心、外塑于形”,进行了深入的交流和探讨。<span></span></span><span></p></span><span><p></span><span><span></span>会上,与会代表们围绕习近平总书记“五四”讲话精神,深入交流了在全面实施素质教育的过程中,如何通过“以文化人、育人兴文”,不断推动社会主义核心价值观教育做深做实、做出特色和成效。北京大学、清华大学、上海交通大学、西南民族大学、复旦大学、郑州大学、河北省教育工委等高校及教育行政部门分别就“文化实践育人”、“网络文化育人”、“创新文化育人形式”等热点问题,介绍了其探索高校校园文化建设的实践和经验。<span></span></span><span></p></span><span><p></span><span><span></span>与会代表一致认为,社会主义核心价值体系是引领社会思潮的强大思想武器,是大学校园文化建设的根本。大学校园文化建设,应将社会主义核心价值体系融入其中,体现在校园物质文化建设、精神文化建设和制度文化建设等方面。同时,也应注意处理好文化多样性与凝聚最大共识间的关系,文化传统性、民族性与文化发展现代化、全球化间的关系,文化内涵高雅性与文化活动形式大众化间的关系。<span></span></span><span></p></span>';</span>echo $html;
echo <span>'<span></html></span>'; </span>
header(<span>"Cache-Control: public"</span>); 
Header(<span>"Content-type: application/octet-stream"</span>); 
Header(<span>"Accept-Ranges: bytes"</span>); 
header(<span>'Content-Disposition: attachment; filename=test.doc'); </span>
header(<span>"Pragma:no-cache"</span>); 
header(<span>"Expires:0"</span>); </code>

The effect in the browser
PHP 网页保存为Word文档

The effect in Word
PHP 网页保存为Word文档

Reference article

Three ways to save web pages as word files in PHP
PHP generates a word document from the web page in the program and provides the downloaded code

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how to save PHP web pages as Word documents, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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
Previous article:PHP Include filesNext article:PHP Include files