我使用dompdf作为结果页面。不符合条件的语句仍会在PDF中留下占位符/空格。我使用ob_start来获取HTML并传递给dompdf输出 - 它是否只保存输出到缓冲区?查看源,未执行的语句不可见。
<?php
ob_start();
?>
<html>
<ul>
<?php if($quizData['q2_o5'] == 1){ ?>
<li>Lipsum</li>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et egestas sapien. Curabitur facilisis suscipit est ac auctor. Praesent et tellus malesuada arcu tincidunt condimentum. Donec id risus est.</li>
</ul>
<?php } ?>
<?php if($quizData['q2_o6'] == 1){ ?>
<li>Lipsum</li>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et egestas sapien. Curabitur facilisis suscipit est ac auctor. Praesent et tellus malesuada arcu tincidunt condimentum. Donec id risus est.</li>
</ul>
<?php } ?>
</ul>
</html>
<?php
$html = ob_get_contents();
ob_end_flush();
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
$file_to_save = $_SERVER['DOCUMENT_ROOT'].'/completed/output.pdf';
file_put_contents($file_to_save, $output);
?>