phpphp-shorttags

why would shorthand PHP opening statements not be working?


I am trying to get my Mac setup as a php server, however, as successful as I have been so far, I seem to have run into a bit of bother.

My PHP opening statments are not working... but only the shorthand ones.

This works:

<?php 
  phpinfo();
?>

This doesn't:

<?
  phpinfo();
?>

It's Mac 10.5. Hope that someone can help.

Thanks


Solution

  • In your php.ini, set short_open_tag to On.

    short_open_tag = On
    

    From the docs:

    short_open_tag boolean

    Tells whether the short form (<? ?> ) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?> . Also if disabled, you must use the long form of the PHP open tag (<?php ?> ).

    Edit:

    short_open_tag is PHP_INI_ALL as of 5.3.0, which means that it can be changed anywhere (php.ini, .htaccess, in script). And it was PHP_INI_PERDIR before 5.3.0, which means that it can be set in php.ini and .htaccess. Therefore, you can change its value in most cases even if you don't control the server.

    However, this setting is off by default. If you are going to distribute your script, it won't work on most installations out of the box. In this case, a search/replace to switch to <?php is a good idea.