dqb14659 2016-03-21 03: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 04: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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部