1

im trying to setup my php server to use

<?
echo 'ok';
?>

syntaxis without 'php' inside opening tag. Now my code works like this

<?php
echo 'ok';
?>

How can i achieve this? I tried to install latest version of php, but it still not working.

3
  • 2
    stackoverflow.com/questions/2185320/… Commented Jul 25, 2017 at 21:57
  • 3
    I would recommend you not doing that since short tags aren't open as default anymore. That would make your code less portable, since there might be situations when you can't modify php.ini. <?php will however always work. Commented Jul 25, 2017 at 22:03
  • To support Magnus' comment, PSR-1 (one of the most common coding guidelines for PHP at the moment) says that "PHP code MUST use the long <?php ?> tags or the short-echo <?= ?> tags; it MUST NOT use the other tag variations." Short PHP tags have very much fallen out of fashion. Commented Jul 25, 2017 at 22:13

2 Answers 2

11

ANSWER:

Set short_open_tag=On in your php.ini and restart the server.

CAVEAT:

Short open tags are not used according to PHP coding standard PSR-1 which states:

PHP code MUST use the long <?php ?> tags or the short-echo <?= ?> tags; it MUST NOT use the other tag variations.

The reason for this as mentioned by @Magnus Eriksson is that there may be situations where you do not have access to edit the php.ini and therefore code that uses short tags will be rendered unusable in those environments. Adhere to the standard for maximum portability!

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

Comments

2

You need to edit your php.ini file and turn short_open_tags on short_open_tag = On

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.