In a PHP document with short open tags enabled, the PHP interpreter will see the <?
part of the <?js
tag and will try to parse it as PHP, resulting in this error:
Parse error: syntax error, unexpected T_STRING in ... on line ...
To fix the problem, disable the short form (<? ?>
) of PHP's open tag.
This will now disable the use of <?
and <?=
in your PHP scripts. If your site only uses <?php
tags then this is safe to do; if it uses <?
as well then it is not safe to do as your scripts will no longer function as expected.
There are two ways your Web Host or System Administration will have configured Apache to use PHP:
- Apache loads the PHP interpreter as an Apache module
- Apache runs the PHP interpreter as a CGI binary
Which solution you will use below will depend on how Apache is running PHP in your environment*.
In Apache's .htaccess
file, place the following:
# PHP as an Apache Module
php_value short_open_tag 0
In the global or a local php.ini
file, place the following:
# PHP as a CGI Wrapper
short_open_tag = Off
In either case, you'll want to restart Apache after making any configuration changes to ensure your new settings get picked up.
Note: If your server is configured to run PHP as an Apache module, then you will have the choice of using either a php.ini
or Apache .htaccess
files. However, if your server runs PHP as a CGI wrapper then you will only have the choice of using php.ini
files locally to change settings, as Apache is no longer in complete control of PHP.
When PHP is running as a CGI wrapper, putting PHP settings in to an .htaccess
file will cause the server throw an error.