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

How to modify word in php

藏色散人
藏色散人Original
2021-10-29 10:04:223758browse

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,

Find26856ed044b04d92f13a5d8060a70f5c and add cbfa6c478d298339139d506edd72ca79Print< 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);

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!

Statement:
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