php生成word文档

使用fopen文件操作函数来做,需要注意的直接生成中文文件名会乱码,(生成word和微软的编码不一样)需要转码生成。word内容保持utf8编码就好。

            $file_name = iconv("UTF-8", "GBK", $detail['name']);
            $fp = fopen('./uploads/'.$file_name.'_'.$userid.'.doc', 'w+');
            $fileContent = '';
            $fileContent.= "姓名:".$detail['name']."\r\n";
            $fileContent.= "性别:".$detail['sex']."\r\n";
            $fileContent.= "会员级别:".$detail['member_type']."\r\n";
            $fileContent.= "职务:".$detail['zhiwu']."\r\n";
            $fileContent.= "联系电话:".$detail['phone']."\r\n";
            $fileContent.= "邮箱:".$detail['email']."\r\n";
            $fileContent.= "公司名称:".$detail['gongsi']."\r\n";
            $fileContent.= "公司地址:".$detail['gongsi_dizhi']."\r\n";
            $fileContent.= "助理电话:".$detail['zhuli_dianhua']."\r\n";
            $fileContent.= "助理姓名:".$detail['zhuli_mingzi']."\r\n";
            $fileContent.= "助理邮箱:".$detail['zhuli_youxiang']."\r\n";
            fwrite($fp, $fileContent);
            fclose($fp);    
            echo "<script>alert('添加成功');window.location.href='".site_url()."/index/joinUs';</script>";

 

posted @ 2014-12-02 12:16  静心聆听  阅读(193)  评论(0编辑  收藏  举报