【发布时间】:2019-10-03 01:41:53
【问题描述】:
我正在使用 Laravel 和 phpword。所以在这里我想将html布局从刀片文件导出到word。
但是当我尝试创建它时,出现的错误:
DOMDocument::loadXML(): Opening and ending tag mismatch: link line 1 and head in Entity, line: 1
我的代码:
$content = view('docs.index')->render();
$dom = new DOMDocument();
$dom->loadHTML($content);
$dom->saveHTML();
$phpWord = new PhpWord();
Html::addHtml($phpWord->addSection(), $dom->saveHTML(), true);
$objWriter = IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('doc_index_'.Carbon::now()->format('d-m-y h-i').'.docx');
return view('papers.show')->with('success');
这是我的刀片文件:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Doc HTML</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div>
<p>
Laravel is a web application framework with expressive, elegant syntax. <br />
We believe development must be an enjoyable and creative experience to be truly fulfilling. <br />
Laravel takes the pain out of development by easing common tasks used in many web projects. <br />
</p>
</div>
</body>
</html>
打印我的 $content 变量:
"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>Doc HTML</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div>
<p>
Laravel is a web application framework with expressive, elegant syntax. <br />
We believe development must be an enjoyable and creative experience to be truly fulfilling. <br />
Laravel takes the pain out of development by easing common tasks used in many web projects. <br />
</p>
</div>
</body>
</html>
"""
【问题讨论】:
-
您的刀片文件中某处的标记似乎有错误。
-
@jfadich 我通过添加刀片文件编辑了我的问题
-
你能回显 $content 吗?
-
@AhmedAboud 是的,你现在可以看到了
标签: php html xml laravel phpword