3

我正在尝试根据我拥有的数据库中的信息构建 PDF。当我这样做时,我收到 500 内部服务器错误。引发错误的代码是:

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

当我用 TCPDF 构建我的 PDF 时,我只是包含了这个文件。让我知道是否需要包含一些 TCPDF 代码。我一生都无法弄清楚为什么它不起作用。我的猜测是我错误地使用了 herdoc。

4

2 回答 2

0

通过查看代码的原始格式,它看起来像

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

用制表符缩进。如果在您的实际代码中是这种情况,那么问题是heredoc 的结尾必须是一行的第一件事。如果它完全缩进,它就会破裂。所以如果你的代码是缩进的,它需要看起来像这样:

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

    {other indented code}
}

PS我上面提到的关于使用制表符缩进的观察是在问题被编辑之前,但是枯萎的方式,如果它用制表符或空格缩进,它会中断。此外,Kyle 正确地指出开头标识符也必须紧跟新行。

于 2012-11-21T18:30:16.207 回答
0

我只是复制并粘贴了您的代码。错误来自位于您的<<<EOF行之后的空间。

你有$html = <<<EOF(space).

应该是$html = <<<EOF

于 2012-11-21T18:33:40.490 回答