问题
Possible Duplicate:
Are PHP short tags acceptable to use?
Which is better to use, or considered better practice: <?php
or <?
. I've always wanted to know. Or is it more of a preference for the programmer.
回答1:
<?php
is the official standard. I've never encountered a problem where a browser was confused, but just using <?
can also declare XML and might not be the best habit to form.
I'll tell you this though - other programmers will always appreciate the standard. I would go with <?php
for sure.
回答2:
<?php
- always, definitely.
Several reasons; the biggest being "disambiguates PHP from SGML (e.g. XML)".
回答3:
As of PHP 5.4, <?=
will be available regardless of the short_open_tags
ini parameter, so if you're forward-looking you could get away with using <?=
inside HTML, in place of <?php echo
, however for non-echos always use <?php
as <?
still depends on the ini.
That said, many hosts have only recently adopted 5.3, and 5.4 is only in beta so if this is a library or something that might reach other's servers soon, I'd stick with <?php
for both.
回答4:
I may recommend <?= ;?>
in HTML code. But, I will alawys recommend <?php
whenever because it's standard and less confusion with XML by example.
来源:https://stackoverflow.com/questions/8004578/php-short-open-tag-vs-long-open-tag