开发者

Is there a difference between '<?=' and '<?php'? [duplicate]

This question already has answers her开发者_开发问答e: Closed 11 years ago.

Possible Duplicate:

Are PHP short tags acceptable to use?

I was looking at some sample code and I noticed that the code used

<?=

instead of

<?php

as opening tags, the closing tags were the same as usual, but I was just wondering if there is any different functionality between the two? The file extension of the sample code is also .phtml instead of .php


<?= is not the same as <?php

<?= is the same as <?php echo

<? is the same as <?php


<?= is shorthand for <?php echo ...

It's used like so:

<?=$var1?>

instead of:

<?php echo $var1; ?>


From http://www.php.net/manual/en/language.basic-syntax.phpmode.php:

There are four different pairs of opening and closing tags which can be used in PHP. Two of those, <?php ?> and <script language="php"> </script>, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.

...

Also note that if you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.

So in summary, use <?php ?>.


<?= prints the result of the PHP. It's roughly equivalent to <?php echo ...

<?php of course just starts the code block.


<?= is shorthand for <? echo

so you could write

Hello, <?= $name ?>.

instead of

Hello, <? echo $name ?>.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜