dqb14659 2016-03-21 11:55
浏览 90
已采纳

解析错误:语法错误,C:\ wamp \ www \ calculater \ wp-content \ themes \ calculater \ page.php中的意外“使用”(T_USE)行[duplicate]

This question already has an answer here:

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;
?>

I try to do downloadable PDF script but getting parse error.

</div>
  • 写回答

1条回答 默认 最新

  • dshdsh2016 2016-03-21 12:15
    关注

    You have problem with use of 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.

    Try this code:

    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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试