我正在寻找一种方法来通过 PHP 保持我的 HTML 代码输出干净。
如果查看源代码,结果如下所示:
<section><div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in</p>
<a href="#" class="btn btn-primary">Go somewhere</a> </div>
</div>
</section><section><div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a> </div>
</div></section>
我希望它看起来像这样:
<section>
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in</p>
<a href="#" class="btn btn-primary">Go somewhere</a> </div>
</div>
</section>
<section>
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in</p>
<a href="#" class="btn btn-primary">Go somewhere</a> </div>
</div>
</section>
这是我的 php 输出代码:
ob_start();
include_once ROOT.'/global/header.php';
print $content_output; // the included files
include_once ROOT.'/global/footer.php';
$output = ob_get_contents();
ob_end_clean();
echo $output;
这样做的原因是我正在构建一个脚手架,其中为网站创建块。例如,起始页由 block2、block7、block1 和 block5 组成。最后,客户得到一个干净的 HTML,它由上述块组成。