如何保持PHP“查看源文件”的HTML输出干净 [英] How to keep PHP 'View Source' html output clean

查看:118
本文介绍了如何保持PHP“查看源文件”的HTML输出干净的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本今天已经缠着我检查源出一个网站之后。我使用PHP的输出在我的动态内容的模板。模板只能在HTML开始的,并且干净缩进和格式化。 PHP的内容,然后在添加和缩进,以配合HTML格式化。

This has been bugging me today after checking the source out on a site. I use PHP output in my templates for dynamic content. The templates start out in html only, and are cleanly indented and formatted. The PHP content is then added in and indented to match the html formating.

<ul>
  <li>nav1</li>
  <li>nav2</li>
  <li>nav3</li>
</ul>

变成了:

<ul>
  <?php foreach($navitems as $nav):?>
  <li><?=$nav?></li>
  <?php endforeach; ?>
</ul>

当在HTML输出,封装PHP线下降,但白色的空间用来格式化他们留在并抛出所有的格式不正常的查看源代码。我提到该网站是干净的格式在查看源代码的输出。我应该承担他们正在使用一些模板引擎?也会有什么办法来清理那种模板,我有吗?与出手动删除空白,并在开发端牺牲可读性?

When output in html, the encapsulated PHP lines are dropped but the white space used to format them are left in and throws the view source formatting all out of whack. The site I mentioned is cleanly formatted on the view source output. Should I assume they are using some template engine? Also would there be any way to clean up the kind of templates I have? with out manually removing the whitespace and sacrificing readability on the dev side?

推荐答案

这件事情,就是缠着我了。你能做的最好是用整齐后处理的文本。该行添加到您的网页的开始(并ppared为输出缓冲当你遇到你的第一个PHP的错误与输出缓冲的)混乱:

That's something that's bugging me, too. The best you can do is using tidy to postprocess the text. Add this line to the start of your page (and be prepared for output buffering havoc when you encounter your first PHP error with output buffering on):

ob_start('ob_tidyhandler');

这篇关于如何保持PHP“查看源文件”的HTML输出干净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆