Reputation: 3950
Is it possible to enable php short-open-tag for a single script ??
The solutions that i have gone through mention adding short_open_tag=On
in php.ini
or
php_value short_open_tag 1
to .htaccess
Can't we enable them under a php script like we enable error reporting..??
Upvotes: 2
Views: 2426
Reputation: 173562
TL;DR - No, those are the only two options you have.
If you can't do any of the mentioned methods, you will need a container script that sets the value before including the script with short open tags.
<?php
ini_set('short_open_tag', 'On');
include 'myscript.php';
This will prevent a parse error in myscript.php
due to short open tags.
The documentation isn't very clear about this, but apparently this stopped working since PHP 4 after which it can only be changed using .htaccess
or editing php.ini
. This excerpt seems to imply that it might work from 5.3 onwards:
PHP_INI_ALL in PHP 4.0.0. PHP_INI_PERDIR in PHP < 5.3.0
But that's not the case, as can be seen from answers of Cannot turn off short_open_tag with ini_set
I've lodged a bug report for this documentation issue.
Update
The documentation will be updated to reflect this behaviour more explicitly:
... it's been
PHP_INI_SYSTEM | PHP_INI_PERDIR
since 4.0.1.
Upvotes: 3