**phpword试用说明,php解析word内容,php读取word内容,php获取word内容方法**
```php
namespace app\controller;
use app\BaseController;
class Index extends BaseController
{
public function index(){
echo ' ';
}
public function wordtohtml(){
$file = request()->file('file');
$ext_name = strtolower(pathinfo($file->getOriginalName(), PATHINFO_EXTENSION));
if($ext_name != 'docx'){
exit(result('文件格式不支持,请上传docx格式word文件',401,'校验失败'));
}
if($file->getSize() > 2097152) {
exit(result('文件太大了,请上传小于2MB的word文件',401,'校验失败'));
}
$savename = \think\facade\Filesystem::putFile( 'uploads', $file);
$html = $this->wordParsing($savename);
//print_r();
unlink($savename);
}
//解析word内容并返回html
public function wordParsing($source)
{
//加载word文件 并 通过getSections获取word文档的全部元素
$sections = \PhpOffice\PhpWord\IOFactory::load($source)->getSections();
//定义html变量用于存储word文本内容
$html = '';
//循环所有元素
foreach($sections as $section) { <