0

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?

2
  • 1
    php.net/manual/en/ini.core.php#ini.short-open-tag Commented Jul 21, 2012 at 8:31
  • 1
    This is why it's been a wide spread suggestions since the mid 2000s to always use <?php :) Commented Jul 21, 2012 at 8:32

4 Answers 4

7

Check your short_open_tag setting in php.ini.

Sign up to request clarification or add additional context in comments.

Comments

3

Modify short_open_tag in php.ini

Comments

1

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.

3 Comments

As of PHP 5.4, <?= is always available regardless of what short_open_tag is set to.
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."
I 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.
1

Using just <? ?> is bad practice so use <?php ?> or edit short_open_tag in your php.ini file.

3 Comments

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.
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
True except it's a feature of PHP so it's still technically correct hehe Feature or bug?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.