如何启用PHP短标签?

发布于 2024-08-19 20:21:51 字数 415 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

向地狱狂奔 2024-08-26 20:21:51

设置

short_open_tag=On

php.ini

并重新启动 Apache 服务器。

Set

short_open_tag=On

in php.ini

And restart your Apache server.

隐诗 2024-08-26 20:21:51

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

short_open_tag = on

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

php_value short_open_tag 1

对于那些认为 Short_open_tags 是不好做法的人从 php 5.4 开始, Shorttag 将在所有地方得到支持,无论设置如何,如果您可以控制服务器上的设置,就没有理由不使用它们。在此链接中还提到: short_open_tag

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

short_open_tag = on

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:

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

灰色世界里的红玫瑰 2024-08-26 20:21:51

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

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

 php --ini

您将得到类似这样的内容,

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

请参阅注释输出中的第二行。该文件将位于提到的路径中。

2.打开php.ini文件并找到short_open_tag。默认情况下,它处于off 状态,将其更改为on

3.重启服务器,执行此评论

service httpd restart

谢谢

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

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

 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.Open php.ini file and find short_open_tag. By default it is in off change it to on.

3.Restart the server,execute this comment

service httpd restart

Thanks

十秒萌定你 2024-08-26 20:21:51

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

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

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

sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php5/apache2/php.ini
驱逐舰岛风号 2024-08-26 20:21:51

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

Go to php.ini and set short_open_tag = On

重要提示:然后您必须重新启动 php -fpm 进程,这样就可以工作了!

sudo service php-fpm restart

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

sudo service nginx restart

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

Go to php.ini and set short_open_tag = On

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

sudo service php-fpm restart

and then finally restart your nginx/http server

sudo service nginx restart
霊感 2024-08-26 20:21:51

您需要打开short_open_tags。

short_open_tag = On

you need to turn on short_open_tags.

short_open_tag = On
寂寞美少年 2024-08-26 20:21:51

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

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

    short_open_tag = 开
    
  3. 重新启动服务器

As simple, as that, follow the following steps:

  1. Go to php.ini file
  2. Find short_open_tag and set it to on

    short_open_tag = On
    
  3. Restart the server

属性 2024-08-26 20:21:51

在 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

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

php_value[short_open_tag] =  On

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:

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:

php_value[short_open_tag] =  On
倾听心声的旋律 2024-08-26 20:21:51

如果您使用 UbuntuApache+php5,那么在当前版本上,有 2 个地方需要更改为 short_open_tag = On

  1. /etc/php5/apache2/php.ini - 这是通过 Web 服务器 (Apache) 加载的页面
  2. /etc/php5/cli/php.ini - 此配置是当您从命令行启动 php 文件时使用,例如: php yourscript.php - 适用于直接在服务器上手动或 cronjob 执行的 php 文件。

If you are using Ubuntu with Apache+php5, then on current versions there are 2 places where you need to change to 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.
第几種人 2024-08-26 20:21:51

如果您编辑 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

深海蓝天 2024-08-26 20:21:51

对于 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

空城之時有危險 2024-08-26 20:21:51
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
;short_open_tag=Off   <--Comment this out
; XAMPP for Linux is currently old fashioned
short_open_tag = On   <--Uncomment this
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
;short_open_tag=Off   <--Comment this out
; XAMPP for Linux is currently old fashioned
short_open_tag = On   <--Uncomment this
顾北清歌寒 2024-08-26 20:21:51

您可以按照以下步骤操作:

1->转到 /etc/php/7.3/apache2PHP 版本 中的 php.ini 文件,然后

2->;找到 short_open_tag 并将其设置为 On 并从开头删除 ;

short_open_tag = On

3->重新启动服务器

sudo service apache2 restart

You can follow the following steps:

1-> Go to php.ini file inside /etc/php/7.3/apache2 or inside your PHP version and

2-> Find short_open_tag and set it to On and removing ; from starting.

short_open_tag = On

3-> Restart the server

sudo service apache2 restart
ぺ禁宫浮华殁 2024-08-26 20:21:51

如果使用 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

萌无敌 2024-08-26 20:21:51

如果您在 Windows 中使用 xampp,请执行以下操作:

  1. 打开 XAMPP 控制面板。
  2. 单击“配置”按钮。
  3. 转到 PHP (php.ini) 选项。

使用ctrl+f实用程序查找short_open_tag

您会发现;short_open_tag

请从行中删除分号(;)

并将其保持为 short_open_tag = on

最后,重新启动 Apache 服务器

If you are using xampp in windows then please do following

  1. Open XAMPP control panel.
  2. Click on CONFIG button.
  3. Go to PHP (php.ini) option.

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

起风了 2024-08-26 20:21:51
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php/7.2/apache2/php.ini

这适用于 ubuntu 16 上的 php7.2,与 Bradley Flood 的上述答案相同,尽管存储配置文件的目录已更改。

您还可以更改 php 字符串中的版本以匹配您当前安装的版本。

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

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.

七颜 2024-08-26 20:21:51

对于 docker 将此步骤添加到 Dockerfile

  ARG phpIniPath=/path/to/your/php.ini

  RUN sed -i -e 's/^short_open_tag\s*=.*/short_open_tag = On/' $phpIniPath  

For docker add this step to Dockerfile

  ARG phpIniPath=/path/to/your/php.ini

  RUN sed -i -e 's/^short_open_tag\s*=.*/short_open_tag = On/' $phpIniPath  
-小熊_ 2024-08-26 20:21:51

要使用 php-fpm 为特定域启用 Short_open_tag,您必须编辑:

/etc/php5/fpm/pool.d/xxxxxxxxxx.conf

其中 xxxxx 是域的套接字号。

并添加: php_value[short_open_tag] = On

To enable short_open_tag for a particular domain with php-fpm, you must edit :

/etc/php5/fpm/pool.d/xxxxxxxxxx.conf

Where xxxxx is the socket number of the domain.

And add : php_value[short_open_tag] = On

爱冒险 2024-08-26 20:21:51
 short_open_tag = On

在 php.ini 中
并重新启动您的 Apache 服务器。

 short_open_tag = On

in php.ini
And restart your Apache Server.

会发光的星星闪亮亮i 2024-08-26 20:21:51

我已将我的 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文件

引擎 = 开启

;该指令决定 PHP 是否能够识别之间的代码
; 应该使用这个功能
;应禁用,因为启用它可能会导致生成 XML 时出现问题
;文档,但是出于向后兼容性的原因,这仍然受到支持。
;请注意,该指令不控制 标签   
; http://php.net/asp-tags
asp_tags = 开

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

engine = On

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It is
; generally recommended that <?php and ?> should be used and that this feature
; should be disabled, as enabling it may result in issues when generating XML
; documents, however this remains supported for backward compatibility reasons.
; Note that this directive does not control the <?= shorthand tag, which can be
; used regardless of this directive. 
; Default Value: On   
; Development Value: Off     
; Production Value: Off  
; http://php.net/short-open-tag

short_open_tag = On

; Allow ASP-style <% %> tags   
; http://php.net/asp-tags
asp_tags = On
捶死心动 2024-08-26 20:21:51

在文件 \apache\Apache2.2.21\bin\php.ini中设置 asp_tags = Onshort_open_tag = On \bin\php\php5.3.8\php.ini 然后重新启动apache服务器。

Set the asp_tags = On and short_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文