Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

PHP short_open_tag 設定說明與啟用方法

編輯:Linux 教學

問題背景

使用 phpcms 本地安裝時,環境檢測提示「short_open_tag 必須開啟」。

解決方法

  1. 開啟 php.ini 設定檔。
  2. 尋找 short_open_tag = Off,修改為 short_open_tag = On。
  3. 重新啟動 Web 伺服器(Apache/Nginx + PHP-FPM)。

short_open_tag 功能說明

設定值效果
On允許使用縮寫標籤 <? ?> 及 <?= $var ?>(等同 <? echo $var ?>)。
Off必須使用完整標籤 <?php ?>。若需輸出 XML 宣告 <?xml version="1.0"?>,需改用 <?php echo '<?xml version="1.0"'; ?> 避免衝突。

建議

現代 PHP 開發建議關閉 short_open_tag,統一使用 <?php 標籤,提升程式碼可攜性與相容性。僅在維護舊專案時暫時開啟。

Copyright © Windows教程網 All Rights Reserved