通过 .htaccess 启用 PHP 短打开标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18956857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:34:12  来源:igfitidea点击:

Enable PHP short open tags via .htaccess

php.htaccessshort-open-tags

提问by David Gard

I'm currently running through a tutorial for a CMS system which unfortunately uses short open tags.

我目前正在浏览一个 CMS 系统的教程,不幸的是它使用了短的开放标签。

I've confirmed that my host will not allow these in their PHP config, but that they run PHP in Apache mode (as opposed to CGI). To the best of my knowledge, this should then allow me to set the short_open_tagflag to onin an .htaccess file.

我已经确认我的主机不会在他们的 PHP 配置中允许这些,但是他们在 Apache 模式下运行 PHP(而不是 CGI)。据我所知,这应该允许我在 .htaccess 文件中设置short_open_tag标志on

However, this appears to not be working. In the root directory, I've created an .htaccess file with just the following line, but the short open tags are still being ignored.

但是,这似乎不起作用。在根目录中,我创建了一个仅包含以下行的 .htaccess 文件,但仍然忽略了短的开放标记。

php_flag short_open_tag on

php_flag short_open_tag on

Am I doing something wrong? If not, can anyone suggest why it may not be working? Thanks.

难道我做错了什么?如果没有,谁能建议为什么它可能不起作用?谢谢。

Note:Someone has marked this question as being answered somewhere else. Not only does the question identified not have an accepted answer, it's based around and PHP config running in CGI mode, not Apache mode.

注意:有人将此问题标记为在别处回答。确定的问题不仅没有公认的答案,而且基于在 CGI 模式下运行的 PHP 配置,而不是 Apache 模式。

回答by geekdev

Try this

尝试这个

 <IfModule mod_php5.c>
   php_value short_open_tag 1
 </IfModule>

This would solve the problem

这将解决问题

回答by garethhallnz

For .htaccessit should be php_value short_open_tag 1For an ini file it's short_open_tag=On.

因为.htaccess它应该是php_value short_open_tag 1对于 ini 文件,它是short_open_tag=On.

If it doesn't work in the .htaccessthen you could try to add you own php.iniin you site root. That said it's unlikely to work.

如果它不起作用,.htaccess那么您可以尝试php.ini在您的站点根目录中添加您自己的内容。那说它不太可能奏效。

Simply put the server admin could have completely disabled this functionality and no matter what you add you will not be able to activate it. It's best you ask your host and save yourself the pain.

简单地说,服务器管理员可以完全禁用此功能,无论您添加什么,您都无法激活它。最好问问你的主人,以免自己受苦。