How to enable PHP short tags?
Set
short_open_tag=On
in php.ini
And restart your Apache server.
How can we enable php short-open-tag for a single script
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.
PHP 7.2.14 short_open_tag = On ignored
I will first note that this question looks like a duplicate of this one. On the off chance it's not, here's my best answer.
The PHP documentation has a page on the opening tags which says:
PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).
Check phpinfo()
and you may see a section entitled Configure Command which contains compilation options. See if there's an --enable-short-tags
option in there anywhere. If not, listen to @phil and look for a section titled Additional .ini files parsed which may list other ini files that have been parsed.
If your search is as thorough as you suggest in your original post and you still cannot get short tags, it may be turned off in an apache configuration file or the short_open_tag
directive may exist in more than one spot. A PHP.ini directive will override any prior values that might have been set.
A grep search might help. In my PHP info output, I see these values:
Loaded Configuration File - /etc/php5/apache2/php.ini
Scan this dir for additional .ini files - /etc/php5/apache2/conf.d
I can easily search all files in that location with this grep command:
grep -ir 'short_open_tag' /etc/php5/apache2
If you double/triple check all these ini files and restart apache and still can't get short_open_tag setting to work, this value may be set as an apache option. I suggest searching the apache configuration files for any reference to short_open_tag
. The exact directory location may be different on your machine, but this grep command works for me
grep -ir 'short_open_tag' /etc/apache2
You should also keep in mind that your apache configuration may not be set up to even bother with .htaccess files so your attempt to override using .htaccess may be for naught unless you configure apache to actually use the .htaccess file. Assuming your apache configuration does bother parsing your htaccess file, this appears to be covered in another question here on SO.
And finally, if your server is configured to use PHP-FPM, then it uses a pool of PHP processes to handle PHP requests from the web server. If that's the case, you would need to restart php-fpm with this command:
sudo service php7.0-fpm restart
NOTE: this command may vary on different machines.
How to enable short tags in IIS 7.5
For ISS you need to go to "PHP Manager"
Then look for "Manage all settings"
Then search for short_open_tag
Double click on it and give value On
Follow the gif file
Restart the ISS and it will work.
PHP Short hand tags 7.x
Is the correct php.ini being loaded?
<?php phpinfo(); ?>
Check for Loaded Configuration File
How to enable Short Tags in Php7 in Alpine Linux?
php config in alpine is in /etc/php7/
,
so you need to add something like
COPY ./php-overrides.ini /etc/php7/conf.d/
into your Dockerfile, and php-overrides.ini
should have short_open_tag=on
in it
Enable PHP short open tags via .htaccess
Try this
<IfModule mod_php5.c>
php_value short_open_tag 1
</IfModule>
This would solve the problem
Related Topics
Commenting Interpreted Code and Performance
How to Download a File on Clicking the Name of File Using PHP
Trying to Pass Todataurl with Over 524288 Bytes Using Input Type Text
Display an Array in a Readable/Hierarchical Format
Laravel: Where to Store Global Arrays Data and Constants
Installing Pdo Driver on MySQL Linux Server
How to Read Xmp Data from a Jpg with PHP
Write CSV to File Without Enclosures in PHP
Why Preg_Replace Throws Me a "Unknown Modifier" Error
Replace Values in a Uri Query String
How to Sum All Values of a Specific Array Key Recursively
Get Refunded Orders and Refunded Order Items Details in Woocommerce 3
Html5 Audio Says "Live Broadcast" in iOS When It's a Static File
Laravel Eloquent Orm Transactions
How to Display the Users Profile Pic Using the Facebook Graph API