【问题标题】:echo not working inside variableecho 在变量内部不起作用
【发布时间】:2014-04-09 17:56:17
【问题描述】:

我目前在使用 PHP 时遇到了一个奇怪的(嗯,对我而言)问题。我正在使用 dompdf,因此将输出 HTML 分配给 $output 变量,如下所示:

function ppt_pdf_output() {

// post-ID of referring page needed
$post       = get_post($_POST['postid']);
$category   = get_the_category($_POST['postid']);
$test       = 'Test!';

$output = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>'.$post->post_title.'</title>
<style>
@page {
    margin: 200px 50px 80px 50px;
}

/* more styles */
</style>
</head>
<body>Some content and HTML';
$output .='<table id="contact">Some more HTML and text'. echo $test .'</h1>
<div id="content">' .
    apply_filters('the_content',$post->post_content) . '</div>';
$output .= '</body></html>';

return $output;
}

我没有得到什么:Wordpress 变量在生成的 PDF 中显示得很好,但是只要我想回显一个自定义变量(如本例中的 $test),我就会得到一个空白页(不是空白PDF,但我什至无法生成它)。

我认为这实际上不是与 dompdf 相关的问题,而是与 PHP 相关的问题 - 但我太新手了,无法弄清楚我做错了什么,因此非常感谢任何帮助。

亲切的问候
奥利

【问题讨论】:

    标签: php wordpress echo dompdf


    【解决方案1】:

    如果你说的是这条线

    $output .='<table id="contact">Some more HTML and text'. echo $test .'</h1>
    <div id="content">' .
    

    你不需要做 echo 你可以连接为

    $output .='<table id="contact">Some more HTML and text'. $test .'</h1>
    <div id="content">' . 
    

    【讨论】:

    • "You can concatenate" 可能不够强大,因为 PHP 会抛出错误并停止执行(这是他看到的行为)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2017-11-12
    • 2015-02-16
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    相关资源
    最近更新 更多