<?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">
我最近越来越多地看到这种趋势。与传统的评论/笔记相比,它有任何优点或缺点吗?
答案 0 :(得分:3)
如果我错了,请纠正我,但我认为唯一的原因是你使用它,是因为你不会在浏览器的网站视图中看到这些评论。
答案 1 :(得分:1)
使用php添加注释有一个优势,即只有阅读php代码的开发人员才会看到这些注释,而且无法通过查看页面源代码(html)看到这些注释。
答案 2 :(得分:0)
根据我的经验,当您必须评论大块代码/标记时,这种趋势的唯一优势是有价值的,例如与hmtl或javascript混合的php。
话虽如此,最佳做法不建议尽可能混合代码和HTML,但如果必须,最好这样做
<?php /*
//js code
<!--
<script type="text/javascript">
//my js script
</script>
-->
<!--
<p>a bit of commented html</p>
-->
*/ ?>
而不是
//js code
<!--
<script type="text/javascript">
//my js script
</script>
-->
<!--
<p>a bit of commented html</p>
-->
答案 3 :(得分:0)
我宁愿使用它:
<?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;
并且可能不会使用像这样的简单回声。我只是不喜欢混合使用PHP和HTML,这很丑陋。最好使用完整的PHP代码。
答案 4 :(得分:-4)
<?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">