1

I can't find the answer anywhere. Thanks!

Teddy
  • 1,996
  • 5
  • 21
  • 33

5 Answers5

9

Basically,

<? ?> are short tags. However, not every php installation has short tags enabled. Therefore, even though is faster to type than the normal tags (<?php ?>), it may not work if you move your code to another server.

Are PHP short tags acceptable to use?

EDIT: Also, if you're using xml in your web page, you might run into conflicts, as writing <?xml version="1.0"?> will make you run into a PHP error, as xml version="1.0" isn't PHP!

If you're using XML and PHP you may need to <?php echo "<?xml version=\"1.0\""; ?>

Community
  • 1
  • 1
Derek Maciel
  • 1,275
  • 2
  • 12
  • 19
3

In your php.ini, if you want <? and ?> to work, you need to turn on "short tags". However, it is better to write long-tag compliant code in the first place.

Acutally is no difference.

Filip Krstic
  • 713
  • 7
  • 19
2

They both mean the same, with the difference that the short form <? ?> is not always supported/enabled.

Oleh Prypin
  • 33,184
  • 10
  • 89
  • 99
2

There acutally is no difference between the two, the second one is bascially just a shorthand. I personally would recommend using the longer version, because on some systems, the second possibilty is disabled in the php.ini (see short_open_tags).

anroesti
  • 11,053
  • 3
  • 22
  • 33
2

It is always better to use <?php ?> as on some installations of php <? ?> is not supported! If this happens your code will not work!

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Yesterday
  • 561
  • 1
  • 15
  • 31