将 PHP 文件转换为 Word 文档并在浏览器中打开它
Convert PHP file to Word doc and to open it in browser
我喜欢将我的 PHP 文件转换为 Word 文档,我使用了这段代码
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</html>
它运行完美,它提示我 open/save 文档而不是像普通网页一样呈现它。但是我也需要在浏览器中打开相同的页面。
有什么方法可以在网络浏览器中打开 PHP 页面并将其另存为 word 文档。如果可能的话,请给我代码,通过单击按钮提示保存为 Word 文档。
下载时给它传一个参数:
<?php
if( $_GET['action'] == 'download' ) {
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<? } ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</html>
然后有一个link通过了file.php?action=download
我喜欢将我的 PHP 文件转换为 Word 文档,我使用了这段代码
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</html>
它运行完美,它提示我 open/save 文档而不是像普通网页一样呈现它。但是我也需要在浏览器中打开相同的页面。
有什么方法可以在网络浏览器中打开 PHP 页面并将其另存为 word 文档。如果可能的话,请给我代码,通过单击按钮提示保存为 Word 文档。
下载时给它传一个参数:
<?php
if( $_GET['action'] == 'download' ) {
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<? } ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</html>
然后有一个link通过了file.php?action=download