我在 phpword 中使用 Laravel。所以在这里我想将 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>
<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>
<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>
"""
阿晨1998
人到中年有点甜