簡體   English   中英

如何啟用PHP短標簽?

[英]How to enable PHP short tags?

我在 Linux 服務器上有一個以<?

我需要將此應用程序復制到 Windows 環境中,並且一切正常,只是 SQL 語句的呈現方式不同。 我不知道這是否與以<?php而不是<? 因為我不知道從哪里啟用<? PHP.ini所以我把它改成<?php

我知道這兩個語句應該是相同的,但我需要用<? 以確保應用程序完全相同。 這樣我就可以排除另一種可能性。

謝謝

short_open_tag=On

php.ini

並重新啟動您的 Apache 服務器。

這可以通過在php.ini 中啟用short_open_tag來完成:

short_open_tag = on

如果您無權訪問 php.ini,您可以嘗試通過.htaccess文件啟用它們,但如果您使用的是共享主機,托管公司可能會禁用此功能:

php_value short_open_tag 1

對於那些認為 short_open_tags從 php 5.4 開始是不好的做法的人來說, <?= ... ?> shorttag 將在任何地方支持,無論設置如何,如果您可以控制服務器上的設置,則沒有理由不使用它們。 在此鏈接中還說: short_open_tag

這可以通過在 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 行。該文件將位於上述路徑中。

2.打開 php.ini 文件,找到short_open_tag 默認情況下,它處於off將其更改為on

3.重啟服務器,執行此注釋

service httpd restart

謝謝

要在 Ubuntu 上設置從 Vagrant 安裝腳本打開的短標簽:

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

我可以看到以上所有答案僅部分正確。 實際上,所有 21 世紀 PHP 應用程序都將具有 FastCGI 進程管理器(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

就這么簡單,請按照以下步驟操作:

  1. 轉到php.ini文件
  2. 找到short_open_tag並將其設置為on

     short_open_tag = On
  3. 重啟服務器

你需要打開short_open_tags。

short_open_tag = On

在 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

如果您將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 文件。

對於 Wamp Server 用戶,有更簡單的方法:您可以啟用該設置,只需(左鍵)單擊 WampServer 圖標一次,選擇 PHP -> PHP 設置 -> 短打開標記。 稍等片刻,WampServer 將自動重啟您的 PHP 及其 Web 服務。

最初來自: http : //osticket.com/forums/showthread.php?t=3149

如果您編輯了 php.ini 文件,請記住重新啟動您的服務(apache2 等)以使對 php.ini 的編輯生效

; 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

如果使用 xampp,您會注意到 php.ini 文件兩次提到了 short_open_tag 。 啟用第二個到 short_open_tag = On 。 第一個被注釋掉,您可能想取消注釋並編輯它,但它被第二個 short_open_tag 覆蓋

如果您在 Windows 中使用 xampp,請執行以下操作

  1. 打開 XAMPP 控制面板。
  2. 單擊配置按鈕。
  3. 轉到 PHP (php.ini) 選項。

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

你會發現;short_open_tag

請從行中刪除分號(;)

並將其保持為short_open_tag = on

最后,重啟你的 Apache 服務器

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

這適用於 ubuntu 16 上的 php7.2,與 Bradley Flood 的上述答案相同,盡管存儲配置文件的目錄已更改。

您也可以更改 php 字符串中的版本以匹配您當前安裝的版本。

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

1-> 轉到/etc/php/7.3/apache2PHP version php.ini文件,然后

2-> 找到short_open_tag並將其設置為On並刪除; 從開始。

short_open_tag = On

3-> 重啟服務器

sudo service apache2 restart

對於 docker,將此步驟添加到 Dockerfile

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

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

要使用 php-fpm 為特定域啟用 short_open_tag,您必須編輯:

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

其中 xxxxx 是域的套接字號。

並添加: php_value[short_open_tag] = On

 short_open_tag = On

php.ini並重新啟動您的 Apache 服務器。

我在我的 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 之后添加額外的一行 as asp_tags = On在重啟Apache之后它適用於代碼並且我正確地輸出

php.ini 文件

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

在文件\\apache\\Apache2.2.21\\bin\\php.ini\\bin\\php\\php5.3.8\\php.ini設置asp_tags = Onshort_open_tag = On ,然后重新啟動apache 服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM