Teddy
Teddy

Reputation: 2006

What's the difference between <?php ?> and <? ?>

I can't find the answer anywhere. Thanks!

Upvotes: 1

Views: 375

Answers (5)

Derek Maciel
Derek Maciel

Reputation: 1315

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\""; ?>

Upvotes: 9

Yesterday
Yesterday

Reputation: 561

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

Upvotes: 2

anroesti
anroesti

Reputation: 11393

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

Upvotes: 2

Filip Krstic
Filip Krstic

Reputation: 713

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.

Upvotes: 3

Oleh Prypin
Oleh Prypin

Reputation: 34116

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

Upvotes: 2

Related Questions