本文介绍了解析错误:语法错误,在线C:\ wamp \ www \ calculater \ wp-content \ themes \ calculater \ page.php中出现意外的“使用"(T_USE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ob_start();
require_once '\dompdf\autoload.inc.php';
use Dompdf\Dompdf;
//use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new DOMPDF();
$html = "
print_r($_POST);
";
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents("page.pdf", $pdf);
?>
<a href="./page.pdf" download="page.pdf">Download the pdf</a>
<?php
exit;
?>
我尝试做可下载的PDF脚本,但出现解析错误.
I try to do downloadable PDF script but getting parse error.
推荐答案您在使用使用:)
use关键字必须在文件的最外层范围内声明( 全局范围)或内部名称空间声明.这是因为 导入是在编译时而不是在运行时完成的,因此不能 块作用域.
The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.
尝试以下代码:
use Dompdf\Dompdf; ob_start(); require_once '\dompdf\autoload.inc.php'; // instantiate and use the dompdf class $dompdf = new DOMPDF(); $html = " print_r($_POST); "; $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $pdf = $dompdf->output(); file_put_contents("page.pdf", $pdf); ?> <a href="./page.pdf" download="page.pdf">Download the pdf</a> <?php exit; ?>更多推荐
解析错误:语法错误,在线C:\ wamp \ www \ calculater \ wp
发布评论