tags:

views:

312

answers:

6

I am new to php and would like to know if there are any differences between these server tags :

<?php
?>

and

<?
?>
+13  A: 

The first is a safe open and close tag variation, the second is the so called short-open tag. The second one is not always available, use the first option if it's possible. You could check the availability of short open tags in php.ini, at the short_open_tag.

erenon
+1  A: 

There is no difference.

The ability to use <? ?> is defined in your php.ini file - usually accessed only by the server host.

You can find more information here

Daniel May
It's defined usually in php.ini
erenon
php.ini, not phpinfo.ini ;)
ILMV
Ahah! easy mistake to make ;)
Daniel May
+1  A: 

Nothing AFAIK, however I have had servers (shared) where the settings do not support shorthand tags <? ?>, so I usually stick with the <?php ?> for good measure.

ILMV
+27  A: 

The problem with short open tags is that the following:

<?xml version="1.0" ?>

will cause problems if you're allowed to use short tags (i.e. <? and ?>). <?php is less open to misinterpretation.

Whether or not you're allowed to use short tags is defined by the ini directive short_open_tag.

Dominic Rodger
Thanks for pointing out a potential pain point!
Xinxua
+3  A: 

Also I think shorttags are being removed in one of the upcomming releases.

Edit: I was wrong.

Farewell <% They will remove support for the ASP style tags, but the PHP short-code tag will remain - so to those on php general who reckon the short-tag is 'depreceated' - hah! ;)

http://phpmysqldev.blogspot.com/2007/05/php-6.html

Pino
any links to the source?
Xinxua
Updated. Sorry about that.
Pino
+2  A: 

Since the closing tag ?> is always the same, the question only concerns the open tag.

If the php ini setting short_open_tag is set to 1, then it is allowed to use <? if it is set to 0 you must use <?php.

Setting this directive to 1 can cause troubles, if you are also using <?xml ?>.

Therefore it is wise to look at the short open tags as deprecated and not use it.

tharkun