[英]Using PHP for comments inside of HTML
<?php // force Internet Explorer to use the latest rendering engine available ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<?php // mobile meta (hooray!) ?>
<meta name="HandheldFriendly" content="True">
I've seen this trend more and more lately. 我最近越来越看到这种趋势。 Does it have any advantages or disadvantages over the traditional way of leaving comments/notes?
与留下评论/注释的传统方式相比,它有什么优点或缺点吗?
如果我错了,请纠正我,但我认为唯一的原因是您使用了它,因为您不会在浏览器的网站源视图中看到注释。
用php添加注释具有一个优点,即只有阅读php代码的开发人员才能看到这些注释,而通过查看page(html)的源代码无法看到这些注释。
For my experience the only advantage with this trend is valuable when you have to comment large blocks of code/markup, like php mixed with hmtl or javascript. 以我的经验,当您必须注释较大的代码/标记块(例如php和hmtl或javascript混合在一起)时,这种趋势的唯一优势是很有价值的。
That being said, best practices don't recommend mixing code and html when it's possible, but if you have to, it is better do this thing 话虽如此,最佳做法不建议在可能的情况下混合使用代码和html,但如果有必要,最好这样做
<?php /*
//js code
<!--
<script type="text/javascript">
//my js script
</script>
-->
<!--
<p>a bit of commented html</p>
-->
*/ ?>
instead of 代替
//js code
<!--
<script type="text/javascript">
//my js script
</script>
-->
<!--
<p>a bit of commented html</p>
-->
I would rather use this: 我宁愿这样:
<?php
// force Internet Explorer to use the latest rendering engine available
echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">'.PHP_EOL;
// mobile meta (hooray!)
echo '<meta name="HandheldFriendly" content="True">'.PHP_EOL;
and probably not use simple echo's like this. 并且可能不使用像这样的简单回声。 I simply don't like mixing PHP and HTML, it's ugly.
我只是不喜欢混合使用PHP和HTML,这很丑陋。 Better go with full PHP code.
最好使用完整的PHP代码。
<?php echo'<!--- force Internet Explorer to use the latest rendering engine available-->' ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<?php echo'<!--- mobile meta (hooray!)-->' ?>
<meta name="HandheldFriendly" content="True">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.