解析错误:语法错误,在线C:\ wamp \ www \ calculater \ wp

编程入门 行业动态 更新时间:2024-10-24 02:38:02
本文介绍了解析错误:语法错误,在线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

本文发布于:2023-11-02 08:14:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   错误   语法错误   wamp   calculater

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!