tags:

views:

384

answers:

3

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

+12  A: 

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.

Ayman Hourieh
This is the correct solution.To the question author: short_open_tag is a bad idea because you may not always have control of the server your code is run on and I would strongly recommend a quick replace on your project to use the full opening tags.
David Caunt
`short_open_tags` is PHP_INI_ALL changable.
Gumbo
thanks. I checked that the live server has this enabled. I agree it's not good practice to do it in general, but it's ok on this project. I just thought it would be nice to get the laptop sorted so I can take my work home :) Thanks for the good advice and points though.
Tisch
A: 

Check if your php.ini file contains the short_open_tag=1 line.

CMS
A: 

Did you verify that short_open_tag (see here) is enabled in your php.ini?

n3rd