tags:

views:

254

answers:

4
short_open_tag = On

Is it possible?

EDIT

I tried this :

<?php
if (!ini_get('short_open_tag')) {
    ini_set('short_open_tag', 'On');
}
$a=1;



?>
<?=$a;?>

which outputs <?=$a;?>,so it's not working.

+3  A: 

Yes, ini_set() is what you want.

EDIT: Added an example

if (!ini_get('short_open_tag')) {
    ini_set('short_open_tag', 'on');
}
Jay Zeng
Not working in PHP5.3.
I don't think this will work for the author's example as the file has already been parsed by the time `ini_set()` is called. Besides, imo, short_open_tags should always be avoided because of the portability nightmares.
Mike B
@Mike: You are right, I overlooked the question. It sounds like .htaccess will be a better alternative.
Jay Zeng
+1  A: 

Although you can use ini_set, be careful (quoted from the PHP Documentation)

Not all the available options can be changed using ini_set(). There is a list of all available options in the appendix.

If you are changing options like magic_quotes, short_open_tags, that's OK. But if you are going to change safe_mode, enable_dl, etc. you might face certain problems.

Jimmie Lin
+1  A: 

if you want to change it during a session and forget about it later, use ini_get() and ini_set(). If you want to actually modify php.ini programmatically, you can parse the ini file using parse_ini_file, change your options and rewrite back to disk. See here for more

or you can write your own string replacement routine using the normal opening of file, preg_replace() etc..

ghostdog74
+4  A: 

If you are using PHP 5.3 short_open_tag is no longer an option.

http://php.net/manual/en/ini.core.php

Short tags have been deprecated as of PHP 5.3 and may be removed in PHP 6.0.

danielrsmith
Agreed. You can not set short_open_tags at runtime. Souce: http://wiki.php.net/rfc/shortags. I'm not 100% certain that short_open_tags are being deprecated in PHP6 (It's been rumored but I've never seen confirmation) Sources http://www.mail-archive.com/[email protected]/msg41868.html and http://www.mail-archive.com/[email protected]/msg41845.html (but these are 8+ months old)
Mike B
Mike you are correct, for a while they had said that 5.3 would deprecate short tags, but it is no longer posted that they will, I guess we will see.
danielrsmith