PHP short open tag vs long open tag [duplicate]

2019-06-27 16:01发布

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.

4条回答
Evening l夕情丶
2楼-- · 2019-06-27 16:45

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.

查看更多
forever°为你锁心
3楼-- · 2019-06-27 16:51

I may recommend <?= ;?> in HTML code. But, I will alawys recommend <?php whenever because it's standard and less confusion with XML by example.

查看更多
来,给爷笑一个
4楼-- · 2019-06-27 16:54

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

查看更多
甜甜的少女心
5楼-- · 2019-06-27 16:57

<?php - always, definitely.

Several reasons; the biggest being "disambiguates PHP from SGML (e.g. XML)".

查看更多
登录 后发表回答