【问题标题】:Parse error: syntax error, unexpected 'use' (T_USE) in C:\wamp\www\calculater\wp-content\themes\calculater\page.php on line [duplicate]解析错误:语法错误,C:\wamp\www\calculator\wp-content\themes\calculator\page.php 中的意外“使用”(T_USE)在线 [重复]
【发布时间】:2016-07-07 22:08:00
【问题描述】:
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 脚本,但出现解析错误。

【问题讨论】:

  • 告诉我们更多信息以继续。
  • 使用语句需要在文件顶部
  • 你运行的是 PHP >= 5.3.0,对吗?

标签: php wordpress namespaces syntax-error


【解决方案1】:

您在使用use时遇到问题:)

use 关键字必须在文件的最外层范围内声明( 全局范围)或内部命名空间声明。这是因为 导入是在编译时而不是运行时完成的,所以它不能 块作用域。

试试这个代码:

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文件的全文吗?这次你有什么错误?
  • $file_location = $_SERVER['DOCUMENT_ROOT']."pdf/".$pdf.".pdf"; file_put_contents($file_location,$pdf);不工作 pdf 保存到所有时间不同的名称警告:file_put_contents() 期望参数 1 是有效路径,
猜你喜欢
  • 2012-06-19
  • 1970-01-01
  • 2013-09-19
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
  • 2013-09-11
  • 1970-01-01
相关资源
最近更新 更多