php 如何启用PHP短标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2185320/
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 05:24:16  来源:igfitidea点击:

How to enable PHP short tags?

phptagsphp-shorttags

提问by seedg

I have a web application on a Linux server which starts with <?

我在 Linux 服务器上有一个 Web 应用程序,它以 <?

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 <?phpinstead of <?because I don't know from where to enable the <?from the PHP.iniso I changed it to <?php

我需要将此应用程序复制到 Windows 环境中,并且一切正常,只是 SQL 语句的呈现方式不同。我不知道这是否与以<?php而不是开头的脚本有关,<?因为我不知道从哪里启用<?fromPHP.ini所以我将其更改为<?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

谢谢

回答by codaddict

Set

short_open_tag=On

in php.ini

php.ini

And restart your Apache server.

并重新启动您的 Apache 服务器。

回答by RJD22

This can be done by enabling short_open_tagin php.ini:

这可以通过在php.ini 中启用short_open_tag来完成:

short_open_tag = on

If you don't have access to the php.ini you can try to enable them trough the .htaccessfile but it's possible the hosting company disabled this if you are on shared hosting:

如果您无权访问 php.ini,您可以尝试通过.htaccess文件启用它们,但如果您使用的是共享主机,托管公司可能会禁用此功能:

php_value short_open_tag 1

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

对于那些认为 short_open_tags从 php 5.4 开始<?= ... ?>是不好的做法的人来说,无论设置如何,shorttag 都将支持任何地方,因此如果您可以控制服务器上的设置,则没有理由不使用它们。在此链接中还说:short_open_tag

回答by user2086641

This can be done by enabling short_open_tag in php.ini:

这可以通过在 php.ini 中启用 short_open_tag 来完成:

1.To locate php.ini file,on comment line execute

1.找到php.ini文件,在注释行执行

 php --ini

you will get some thing like this,

你会得到这样的东西,

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/curl.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/json.ini,
/etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/zip.ini

See 2nd line from the comment output.The file will be in the mentioned path.

请参阅注释输出中的第 2 行。该文件将位于上述路径中。

2.Open php.ini file and find short_open_tag. By default it is in offchange it to on.

2.打开 php.ini 文件,找到short_open_tag. 默认情况下,off将其更改为on.

3.Restart the server,execute this comment

3.重启服务器,执行此注释

service httpd restart

Thanks

谢谢

回答by Bradley Flood

To set short tags to open from a Vagrant install script on Ubuntu:

要在 Ubuntu 上设置从 Vagrant 安装脚本打开的短标签:

sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php5/apache2/php.ini

回答by Eddy Ferreira

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

我可以看到以上所有答案仅部分正确。实际上,所有 21 世纪 PHP 应用程序都将具有 FastCGI 进程管理器(php-fpm),因此一旦您将 php-info() 添加到 test.php 脚本中并检查了 php.ini 的正确路径

Go to php.ini and set short_open_tag = On

IMPORTANT: then you must restart your php-fpm process so this can work!

重要提示:那么你必须重新启动你的 php-fpm 进程,这样才能工作!

sudo service php-fpm restart

and then finally restart your nginx/http server

然后最后重启你的 nginx/http 服务器

sudo service nginx restart

回答by Suresh KUMAR Mukhiya

As simple, as that, follow the following steps:

就这么简单,请按照以下步骤操作:

  1. Go to php.inifile
  2. Find short_open_tagand set it to on

    short_open_tag = On
    
  3. Restart the server

  1. 转到php.ini文件
  2. 找到short_open_tag并将其设置为on

    short_open_tag = On
    
  3. 重启服务器

回答by Jage

you need to turn on short_open_tags.

你需要打开short_open_tags。

short_open_tag = On

回答by XakRu

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:

在 CentOS 6(也在 CentOS 7 上测试)中,您不能在 /etc/php.ini 中为 php-fpm 设置 short_open_tag。你会遇到错误:

ERROR: [/etc/php.ini:159] unknown entry 'short_open_tag'
ERROR: Unable to include /etc/php.ini from /etc/php-fpm.conf at line 159
ERROR: failed to load configuration file '/etc/php-fpm.conf'
ERROR: FPM initialization failed

You must edit config for your site, which can found in /etc/php-fpm.d/www.conf And write at end of file:

您必须为您的站点编辑配置,可以在 /etc/php-fpm.d/www.conf 中找到并在文件末尾写入:

php_value[short_open_tag] =  On

回答by Vladas Freimanas

If you are using Ubuntuwith Apache+php5, then on current versions there are 2 places where you need to change to short_open_tag = On

如果您正在使用Ubuntuwith Apache+php5,那么在当前版本中,您需要将 2 个地方更改为short_open_tag = On

  1. /etc/php5/apache2/php.ini- this is for the pages loaded through your web server (Apache)
  2. /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.
  1. /etc/php5/apache2/php.ini- 这是用于通过您的 Web 服务器 (Apache) 加载的页面
  2. /etc/php5/cli/php.ini- 当您从命令行启动 php 文件时使用此配置,例如:php yourscript.php- 直接在服务器上手动或 cronjob 执行的 php 文件。

回答by Steve Wasiura

if you edit your php.ini file, remember to restart your service (apache2, etc) for the edits to php.ini to take effect

如果您编辑了 php.ini 文件,请记住重新启动您的服务(apache2 等)以使对 php.ini 的编辑生效