php下载各种编辑器输出的内容到word中展示

<?php
/**
* Created by PhpStorm.
* User: 工作
* Date: 2018/1/11
* Time: 12:02
*/

//连接数据库
$dsn = "mysql:host=localhost;dbname=phpcmsv9";
$db = new PDO($dsn, 'root', 'root');
$db->query("set names utf8");
$sql="select content from v9_news_data where id='45'";
$a=$db->query($sql)->fetchall(PDO::FETCH_ASSOC);
echo '<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">';
print_r($a[0]['content']);



ob_start(); //打开缓冲区
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();//输出全部内容到浏览器

posted on 2018-01-11 15:24  骄傲做自己  阅读(207)  评论(0编辑  收藏  举报

导航