Using <?php ?> VS. <? ?>
Possible Duplicate:
Are PHP short tags acceptable to use?
We are currently using a mix of both styles for writing php code inside our phtml files. Nothing seems to be breaking but I'm just curious about using one over another.
(looking for something more then.. 'its best practice' answer)
<?=$var?>
is the only sensible way to output a variable if you're using PHP templates. Writing each variable on the page as <?php echo $var ?>
is a pain. So, if you're a masochist (or using different template), go for the long form, otherwise stick with short (at least in templates)
<? ?>
<? ?>
are called short tags, they need to be enabled on the server in the php ini file. The only reason why you should not use them is because of compatibility, which in my opinion is not that big a deal, but if you are writing a CMS that is supposed to be used by other people on other servers you should use normal tags <?php ?>
The <? ?>
<? ?>
syntax needs to be set to "on" in php.ini, so it may not work
<?php ?>
always works.
上一篇: <?php vs <? ...有关系吗?
下一篇: 使用<?php?> VS. <? ?>