简体   繁体   中英

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.

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

<?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. Better go with full PHP code.

<?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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM