网站建设技术团队
php修改word内容
  • 日期 : 2012-04-10

1.先将word另存为网页,取名ytwl.mht

2.修改为默认页面视图,用dreamweaver打开ytwl.mht ,

找到

找到在下面加上Print  然后保存.

3.编写php代码
ob_start();//开启缓存
  print'';//">http://www.w3.org/TR/REC-html40">';//输出头部
 

  
  $content = file_get_contents(S_ROOT.'./temp/word/ytwl.htm');//取得模板内容
  
  $content = str_replace('<{ytwl_company_name}>',"英特网路",$content);//经过一列替换操作,将会模板里的标签替换为接受的值,如果感觉有必要的话,用正则替换也行,但我不建议动不动就用正则,能不用就不用吧!
  
  $docname = 'ytwl.doc';//生成保存的文件名,后缀为doc
  
  echo $content;//将替换后的内容输出到缓存中
  
  print "";
  $data = ob_get_contents();
  ob_end_clean();
  
  $fp=fopen(S_ROOT.'./temp/word/'.$docname,"wb");//以二进制写权限打开一个新的word文件,即新建
  fwrite($fp,$data);//将内容写入并 保存
  fclose($fp);