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.

Dmitry Yudin
  • 1,033
  • 1
  • 10
  • 31
  • 2
    https://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags – arkascha Jul 25 '17 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. ` – M. Eriksson Jul 25 '17 at 22:03
  • To support Magnus' comment, [PSR-1](http://www.php-fig.org/psr/psr-1/) (one of the most common coding guidelines for PHP at the moment) says that "PHP code MUST use the long `` tags or the short-echo `= ?>` tags; it MUST NOT use the other tag variations." Short PHP tags have very much fallen out of fashion. – ChrisGPT was on strike Jul 25 '17 at 22:13

2 Answers2

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!

Ryan Tuosto
  • 1,941
  • 15
  • 23
2

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

Kevin P
  • 601
  • 3
  • 9