解析错误:语法错误,在线C:\ wamp \ www \ calculater \ wp-content \ themes \ calculater \ page.php中出现意外的“使用"(T_USE) [英] Parse error: syntax error, unexpected 'use' (T_USE) in C:\wamp\www\calculater\wp-content\themes\calculater\page.php on line

查看:101
本文介绍了解析错误:语法错误,在线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-content \ themes \ calculater \ page.php中出现意外的“使用"(T_USE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆