如何启用PHP短标签?
我在 Linux 服务器上有一个以 开头的 Web 应用程序,
我需要将此应用程序复制到 Windows 环境,除了 SQL 语句的呈现方式不同之外,一切都工作正常。我不知道这是否与以 而不是
开头的脚本有关,因为我不知道从哪里启用 < code> 来自
PHP.ini
所以我将其更改为
我知道这两个语句应该含义相同,但是我需要使用 对其进行测试,以确保应用程序完全相同。这样我就可以排除另一种可能性。
谢谢
I have a web application on a Linux server which starts with <?
I needed to copy this application to a windows environment and everything is working fine except that an SQL statement is being rendered differently. I don't know if this has to do with the script beginning with <?php
instead of <?
because I don't know from where to enable the <?
from the PHP.ini
so I changed it to <?php
I know that these 2 statements are supposed to mean the same but I need to test it with <?
in order to ensure that the application is exactly the same. This way I can eliminate another possibility.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
设置
在 php.ini 中
并重新启动 Apache 服务器。
Set
in php.ini
And restart your Apache server.
这可以通过启用 short_open_tag 来完成在 php.ini 中:
如果您无权访问 php.ini,您可以尝试通过 .htaccess 文件启用它们,但托管公司可能禁用了此功能如果您使用共享主机:
对于那些认为 Short_open_tags 是不好做法的人从 php 5.4 开始,
Shorttag 将在所有地方得到支持,无论设置如何,如果您可以控制服务器上的设置,就没有理由不使用它们。在此链接中还提到: short_open_tag
This can be done by enabling short_open_tag in php.ini:
If you don't have access to the php.ini you can try to enable them trough the .htaccess file but it's possible the hosting company disabled this if you are on shared hosting:
For the people thinking that short_open_tags are bad practice as of php 5.4 the
<?= ... ?>
shorttag will supported everywhere, regardless of the settings so there is no reason not to use them if you can control the settings on the server. Also said in this link: short_open_tag这可以通过在 php.ini 中启用 Short_open_tag 来完成:
1.要找到 php.ini 文件,在注释行执行时
您将得到类似这样的内容,
请参阅注释输出中的第二行。该文件将位于提到的路径中。
2.打开php.ini文件并找到
short_open_tag
。默认情况下,它处于off
状态,将其更改为on
。3.重启服务器,执行此评论
谢谢
This can be done by enabling short_open_tag in php.ini:
1.To locate php.ini file,on comment line execute
you will get some thing like this,
See 2nd line from the comment output.The file will be in the mentioned path.
2.Open php.ini file and find
short_open_tag
. By default it is inoff
change it toon
.3.Restart the server,execute this comment
Thanks
要设置短标签以从 Ubuntu 上的 Vagrant 安装脚本打开:
To set short tags to open from a Vagrant install script on Ubuntu:
我可以看到上面的所有答案仅部分正确。
实际上,所有 21 世纪的 PHP 应用程序都会有 FastCGI Process Manager(php-fpm),因此一旦您将 php-info() 添加到 test.php 脚本中并检查了 php.ini 的正确路径,
重要提示:然后您必须重新启动 php -fpm 进程,这样就可以工作了!
然后最后重新启动你的 nginx/http 服务器
I can see all answers above are partially correct only.
In reality all 21st Century PHP apps will have FastCGI Process Manager(php-fpm) so once you have added php-info() into your test.php script and checked the correct path for php.ini
IMPORTANT: then you must restart your php-fpm process so this can work!
and then finally restart your nginx/http server
您需要打开short_open_tags。
you need to turn on short_open_tags.
就这么简单,按照以下步骤操作:
php.ini
文件找到
short_open_tag
并将其设置为on
重新启动服务器
As simple, as that, follow the following steps:
php.ini
fileFind
short_open_tag
and set it toon
Restart the server
在 CentOS 6 中(也在 Centos 7 上测试过),您无法在 /etc/php.ini 中为 php-fpm 设置short_open_tag。
您将收到错误:
您必须编辑站点的配置,可以在 /etc/php-fpm.d/www.conf 中找到
并在文件末尾写入:
In CentOS 6(tested on Centos 7 too) you can't set short_open_tag in /etc/php.ini for php-fpm.
You will have error:
You must edit config for your site, which can found in /etc/php-fpm.d/www.conf
And write at end of file:
如果您使用
Ubuntu
和Apache+php5
,那么在当前版本上,有 2 个地方需要更改为short_open_tag = On
/etc/php5/apache2/php.ini
- 这是通过 Web 服务器 (Apache) 加载的页面/etc/php5/cli/php.ini
- 此配置是当您从命令行启动 php 文件时使用,例如:php yourscript.php
- 适用于直接在服务器上手动或 cronjob 执行的 php 文件。If you are using
Ubuntu
withApache+php5
, then on current versions there are 2 places where you need to change toshort_open_tag = On
/etc/php5/apache2/php.ini
- this is for the pages loaded through your web server (Apache)/etc/php5/cli/php.ini
- this configuration is used when you launch your php files from command line, like:php yourscript.php
- that goes for manually or cronjob executed php files directly on the server.如果您编辑 php.ini 文件,请记住重新启动服务(apache2 等)以使对 php.ini 的编辑生效
if you edit your php.ini file, remember to restart your service (apache2, etc) for the edits to php.ini to take effect
对于 Wamp Server 用户来说,有更简单的方法:
您只需(左键)单击 WampServer 图标一次,然后选择 PHP -> 即可启用该设置。 PHP设置->短开放标签。稍等片刻,WampServer 将自动重新启动您的 PHP 及其 Web 服务。
最初来自:http://osticket.com/forums/showthread.php?t=3149< /a>
For Wamp Server users there is easier way:
You may enable that setting simply (left) click once on the WampServer icon, choose PHP -> PHP settings -> short open tag. Wait for a second, then WampServer will automatically restart your PHP and also its web service.
originally from: http://osticket.com/forums/showthread.php?t=3149
您可以按照以下步骤操作:
1->转到
/etc/php/7.3/apache2
或PHP 版本
中的php.ini
文件,然后2->;找到
short_open_tag
并将其设置为On
并从开头删除;
。3->重新启动服务器
You can follow the following steps:
1-> Go to
php.ini
file inside/etc/php/7.3/apache2
or inside yourPHP version
and2-> Find
short_open_tag
and set it toOn
and removing;
from starting.3-> Restart the server
如果使用 xampp,您会注意到 php.ini 文件两次提到了 Short_open_tag 。将第二个启用为short_open_tag = On。第一个已被注释掉,您可能想取消注释并编辑它,但它被第二个 Short_open_tag 覆盖
if using xampp, you will notice the php.ini file has twice mentioned short_open_tag . Enable the second one to short_open_tag = On . The first one is commented out and you might be tempted to uncomment and edit it but it is over-ridden by a second short_open_tag
如果您在 Windows 中使用 xampp,请执行以下操作:
使用ctrl+f实用程序查找short_open_tag
您会发现
;short_open_tag
请从行中删除分号(;)。
并将其保持为
short_open_tag = on
最后,重新启动 Apache 服务器
If you are using xampp in windows then please do following
Find short_open_tag using ctrl+f utility
You will found
;short_open_tag
kindly remove the semicolon (;) from line.
and keep it as
short_open_tag = on
Finally, restart your Apache server
这适用于 ubuntu 16 上的 php7.2,与 Bradley Flood 的上述答案相同,尽管存储配置文件的目录已更改。
您还可以更改 php 字符串中的版本以匹配您当前安装的版本。
That works on php7.2 on ubuntu 16, same answer as above by Bradley Flood, although the directory in which the config file is stored has changed.
Also you can change the version in the php string to match your currently installed version.
对于 docker 将此步骤添加到 Dockerfile
For docker add this step to Dockerfile
要使用 php-fpm 为特定域启用 Short_open_tag,您必须编辑:
其中 xxxxx 是域的套接字号。
并添加: php_value[short_open_tag] = On
To enable short_open_tag for a particular domain with php-fpm, you must edit :
Where xxxxx is the socket number of the domain.
And add : php_value[short_open_tag] = On
在 php.ini 中
并重新启动您的 Apache 服务器。
in
php.ini
And restart your Apache Server.
我已将我的 aws centos 7 实例和 php7(PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )) 上的 Short_open_tag Off 更改为 On,但它没有反映 php 信息页面和代码。所以我参考了可能的文档并找到了针对我的案例的解决方案。在short_open_tag后面添加一行额外的代码作为asp_tags = On,然后重新启动Apache它可以在代码上运行,并且我可以正确输出
php.ini文件
I'v Changed the short_open_tag Off to On on my aws centos 7 instance and php7(PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )), but its not reflecting the php info page and the code. So I refer may docs and find a solution on my case. Add an extra line after the short_open_tag as asp_tags = On after that restart Apache It works on the code and I go the output correctly
php.ini file
在文件
\apache\Apache2.2.21\bin\php.ini
和中设置
然后重新启动apache服务器。asp_tags = On
和short_open_tag = On
\bin\php\php5.3.8\php.iniSet the
asp_tags = On
andshort_open_tag = On
in both the files\apache\Apache2.2.21\bin\php.ini
and\bin\php\php5.3.8\php.ini
and then restart the apache server.