I've just installed apache 2.2.22, php 5.3.15 and some other stuff on my Windows 7. At some point, the tag <?
stopped working (apache now returns <? ..... ?>
as plain HTML). After wasting a lot of time, I noticed that the full version of this tag <?php
does work! How can I fix it without editing the code?
4 Answers
You must enable php short tags for <?
and <?=
to work in PHP < 5.4. Call ini_set('short_open_tag', true)
or modify your php.ini if you can to specify it. Some hosts even allow a php.ini within the directory of the php script itself or you can customize your php.ini through your hosting panel.
-
As of PHP 5.4,
<?=
is always available regardless of whatshort_open_tag
is set to. Jul 23, 2012 at 15:38 -
Yes, I know that but in his question he said "I've just installed apache 2.2.22, php 5.3.15 and some other stuff on my Windows 7." Jul 23, 2012 at 19:56
-
1I understand, I just left the comment because in a vacuum your opening sentence is not true anymore and I don't want anyone stumbling across your answer in the future to get the wrong idea. Jul 23, 2012 at 21:03
Using just <? ?>
is bad practice so use <?php ?>
or edit short_open_tag
in your php.ini file.
-
Not necessarily. Most hosts now allow some form of overriding so server compatibility does not remain an issue. There are also one-off cases where it creates an error, i.e. when outputting xml inside of a php template. Jul 21, 2012 at 8:35
-
Yes it depends on the person's views but there is nothing wrong with short tags. In fact it reduces the amount of typing you have to do. The side effects are very mimimal and if you use SCM you can include the php.ini file or even use php_value inside of htaccess Jul 21, 2012 at 8:43
-
True except it's a feature of PHP so it's still technically correct hehe Feature or bug? Jul 21, 2012 at 9:04
<?php
:)