PHP读取HTML生成doc

PHP代码如下:

<?php 

//获取1.html文档的内容(包括html代码)
$result = file_get_contents('./word.html');
echo "$result";  

// /保存///
//打开缓冲区  
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(); 


?>

HTML代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>PHP生成Word文档</title>
    <meta charset="utf-8">
</head>
<body>

    <h1 style="text-align: center">xxx的简历</h1>  
    <h3>编号:000001</h3>  
    <table border="1" cellpadding="3" cellspacing="0" >  
        <tr >  
            <td width="93" valign="center" colspan="2" >姓名</td>  
            <td width="160" valign="center" colspan="4" >xxx</td>  
            <td width="89" valign="center" colspan="2" >学历</td>  
            <td width="156" valign="center" colspan="3" >xxx</td>  
            <td width="125" colspan="2" rowspan="4" align="center" valign="middle" >
                <img src="https://www.baidu.com/img/bd_logo1.png?where=super" width="120" height="120" />
            </td>  
        </tr>  
        <tr >      
            <td width="93" valign="center" colspan="2" >性别</td>  
            <td width="72" valign="center" colspan="2" >xxx</td>  
            <td width="88" valign="center" colspan="2" >出生年月</td>  
            <td width="89" valign="center" colspan="2" >xxx</td>  
            <td width="68" valign="center" >户籍地</td>  
            <td width="87" valign="center" colspan="2" >xxx</td>  
        </tr>  
        <tr >  
            <td width="93" valign="center" colspan="2" >身高</td>  
            <td width="72" valign="center" colspan="2" >xxxcm</td>  
            <td width="88" valign="center" colspan="2" >体重</td>  
            <td width="89" valign="center" colspan="2" >xxxkg</td>  
            <td width="68" valign="center" >婚姻状况</td>  
            <td width="87" valign="center" colspan="2" >xxx</td>  
        </tr>  
        <tr >  
            <td width="93" valign="center" colspan="2" >手机</td>  
            <td width="160" valign="center" colspan="4" >xxx</td>  
            <td width="89" valign="center" colspan="2" >Email</td>  
            <td width="156" valign="center" colspan="3" >xxx</td>  
        </tr>  
        <tr >  
            <td width="93" valign="center" colspan="2"  style="width:93px;">家庭住址</td>  
            <td width="530" valign="center" colspan="11" >xxx</td>  
        </tr>  
        <tr >  
            <td width="93" valign="center" colspan="2" rowspan="3">求职意向</td>  
            <td width="93" valign="center" colspan="2">希望从事职业</td>  
            <td width="200" valign="center" colspan="2">xxx</td>  
            <td width="93" valign="center" colspan="2">希望薪资</td>  
            <td width="200" valign="center" colspan="5">xxx元/月</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" colspan="2" >希望工作地区</td>  
            <td width="200" valign="center" colspan="2" >xxx</td>  
            <td width="93" valign="center" colspan="2" >食宿要求</td>  
            <td width="200" valign="center" colspan="5" >xxx</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" colspan="2" >目前状况</td>  
            <td width="200" valign="center" colspan="9" >xxx</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" style="color: red">自我评价</td>  
            <td width="570" valign="center" colspan="12" >xxx</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" >工作经历</td>  
            <td width="570" valign="center" colspan="12" >xxx</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" >教育经历</td>  
            <td width="570" valign="center" colspan="12" >xxx</td>  
        </tr>  
        <tr>  
            <td width="93" valign="center" >培训经历</td>  
            <td width="570" valign="center" colspan="12" >xxx</td>  
        </tr>  
    </table> 

    <p><a href="./word.php">点击下载</a></p>

</body>
</html>

运行后下载效果:

打开的时候提示

选HTML打开后

 

转载于:https://www.cnblogs.com/lizhaoyao/p/10620300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值