I can't find the answer anywhere. Thanks!
-
8What about the manual? – BoltClock Feb 05 '11 at 17:16
-
1possible duplicate of [shorter way of echoing a variable in php?](http://stackoverflow.com/questions/1656795/shorter-way-of-echoing-a-variable-in-php) – karim79 Feb 05 '11 at 17:18
-
Well said Bolt.. (+1) what is the difference between and :) – Chetan Sharma Feb 05 '11 at 17:18
-
Bolt - Although I see your point, keep in mind this *is* a Q&A site. And this is actually a great title for the question - it will be much easier for someone to find than the dupe. – Justin Ethier Feb 05 '11 at 17:22
5 Answers
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\""; ?>

- 1
- 1

- 1,275
- 2
- 12
- 19
-
-
@BlaXpirit Not at all. I just wrote a sample script, with "" as the code, and I got the following error: Parse error: syntax error, unexpected '<' – Derek Maciel Feb 05 '11 at 17:30
-
Anyways, it's best to simply disable `short_open_tags` in php.ini, as I mentoined in my post. – anroesti Feb 05 '11 at 18:58
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.

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

- 33,184
- 10
- 89
- 99
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
).

- 11,053
- 3
- 22
- 33