duanmorong9597 2012-11-21 17:56 采纳率: 100%
浏览 46
已采纳

Heredoc字符串和TCPDF来构建动态PDF

I am attempting to build a PDF based on the information in a database that I have. I am getting a 500 internal server error when I do. The code that is throwing the error is:

<?php
include('db.php');

    $pdfArray = array();

    $top = '<h1>Med One Equipment List</h1>
            <table>
            <thead>
                <tr>
                    <td>Manufacturer</td>
                    <td>Model</td>
                    <td>Description</td>
                </tr>
            </thead>
            <tbody>
        ';
        array_push($pdfArray, $top);

    while($rowAll = mssql_fetch_array($allResult)) {
        $html = '
        <tr>
            <td>'.$rowAll["Manufacturer"].'</td>
            <td>'.$rowAll["Model"].'</td>
            <td>'.$rowAll["Make"].'</td>
        <tr>';
        array_push($pdfArray, $html);
    }

    $bottom = '</tbody>
                </table>';

    array_push($pdfArray, $bottom);

    $table = implode(" ", $pdfArray);

    $html =  <<<EOF 
    {$table} 
    EOF;
?>

I am just including this file when I build my PDF with TCPDF. Let me know if I need to include some of the TCPDF code. I can't for the life of my figure out why it won't work. My guess is that I'm using herdoc incorrectly.

  • 写回答

2条回答 默认 最新

  • douzhang1115 2012-11-21 18:30
    关注

    From looking at the raw formatting of your code, it looks like

    $html =  <<<EOF
    {$table} 
    EOF;
    

    is indented with a tab. If that is the case in your real code, the problem is that the end of a heredoc must be the first thing on a line. If it is indented at all, it will break. So if your code is indented, it will need to look something like this:

    if($example_block){
        $html =  <<<EOF
        {$table} 
    EOF;
    
        {other indented code}
    }
    

    P.S. The observations about the indenting with a tab I mentioned above were from before the question was edited, but wither way, if it is indented with a tab or spaces, it will break. Also, Kyle is is correct in stating that the opening identifier must also be immediately followed by a new line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)