Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在 PHP 中将 HTML 代码的输出抓取到变量中?基本上,我正在寻找这段代码的简写:
<?php ob_start(); ?> <div class="headSection"> <h1><?=$headline?></h1> <p><?=$bottomline?></p> </div> <?php $contents = ob_get_contents(); ob_end_clean(); ?>
我希望将 HTML 代码保存在$contents变量中。
$contents
使用 PHP 的 EOF 字符串
$str = <<<EOF <div class="headSection"> <h1>$headline</h1> <p>$bottomline</p> </div> EOF; echo $str;
演示http://codepad.org/9OeUiJNJ