gpt4 book ai didi

php - 解析错误 : syntax error, 意外 'use' (T_USE) in C :\wamp\www\calculater\wp-content\themes\calculater\page. php on line

转载 作者:行者123 更新时间:2023-12-03 08:03:19 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





PHP parse/syntax errors; and how to solve them

(20 个回答)


5年前关闭。



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 脚本,但出现解析错误。

最佳答案

您在使用 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;
?>

关于php - 解析错误 : syntax error, 意外 'use' (T_USE) in C :\wamp\www\calculater\wp-content\themes\calculater\page. php on line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36130367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com