Home > Backend Development > PHP Problem > How to modify word in php

How to modify word in php

藏色散人
Release: 2023-03-13 15:12:01
Original
3761 people have browsed it

How to modify word in php: 1. Save word as a web page; 2. Change it to the default page view; 3. Write PHP code; 4. Modify the Word content through functions such as fwrite.

How to modify word in php

The operating environment of this article: Windows 7 system, PHP version 5.6, DELL G3 computer

How to modify word in php?

Use PHP to modify the content of word

Today I will bring you a tutorial to teach you how to use PHP to modify the content of word. The tutorial is as follows:

1. First save word as a web page, named jzydt.mht

2. Change to the default page view, use dreamweaver to open jzydt.mht,

Find< meta http-equiv=3DContent-Type content=3D"text/html; charset=Change the following encoding to utf-8

Find and add Print< below ;/w:View> Then save.

3. Write php code

  ob_start();//开启缓存
  print&#39;<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">&#39;;//输出头部
  $content = file_get_contents(S_ROOT.&#39;./temp/word/jzydt.htm&#39;);//取得模板内容
  $content = str_replace(&#39;<{jzydt_company_name}>&#39;,"400电话",$content);//经过一列替换操作,将会模板里的标签替换为接受的值,如果感觉有必要的话,用正则替换也行,但我不建议动不动就用正则,能不用就不用吧!
  $docname = &#39;jzydt.doc&#39;;//生成保存的文件名,后缀为doc
  echo $content;//将替换后的内容输出到缓存中
  print "</html>";
  $data = ob_get_contents();
  ob_end_clean(); 
  $fp=fopen(S_ROOT.&#39;./temp/word/&#39;.$docname,"wb");//以二进制写权限打开一个新的word文件,即新建
  fwrite($fp,$data);//将内容写入并 保存
  fclose($fp);
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to modify word in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template