2010-01-08 57 views
1
short_open_tag = On 

這可能嗎?如何使用PHP更改php.ini?

編輯

我嘗試這樣做:

<?php 
if (!ini_get('short_open_tag')) { 
    ini_set('short_open_tag', 'On'); 
} 
$a=1; 



?> 
<?=$a;?> 

其輸出<?=$a;?>,所以它不工作。

回答

3

是的,ini_set()是你想要的。

編輯:如果要更改喜歡magic_quotes的,項short_open_tags選項增加了一個例子

if (!ini_get('short_open_tag')) { 
    ini_set('short_open_tag', 'on'); 
} 
+1

在PHP5.3不工作。 – user198729 2010-01-08 04:00:45

+2

我認爲這不會對作者的例子有用,因爲在調用'ini_set()'的時候文件已經被解析了。此外,由於便攜性惡夢,應始終避免使用imo,short_open_tags。 – 2010-01-08 04:07:10

+0

@Mike:你說得對,我忽略了這個問題。這聽起來像.htaccess將是一個更好的選擇。 – 2010-01-08 04:39:22

1

雖然可以使用的ini_set,要小心(從PHP文件的引用)

Not all the available options can be changed using ini_set(). There is a list of all available options in the appendix.

,沒關係。但是,如果您要更改safe_mode,enable_dl等,您可能會遇到某些問題。

1

如果您想在會話期間更改並稍後忘記它,請使用ini_get()和ini_set()。如果您想以編程方式實際修改php.ini,則可以使用parse_ini_file解析ini文件,更改選項並將其重寫回磁盤。如果你正在使用PHP 5.3 short_open_tag不再是一個選項,請參見here更多

,或者您可以使用文件的正常開放,preg_replace函數編寫自己的字符串替換例程()等。

4

http://php.net/manual/en/ini.core.php

短標籤已被棄用的PHP 5.3,並且可以在PHP 6.0中刪除。

+1

同意。運行時不能設置short_open_tags。 Souce:http://wiki.php.net/rfc/shortags。我不是100%確定short_open_tags在PHP6中被棄用(據傳,但我從來沒有見過確認)來源http://www.mail-archive.com/[email protected]/msg41868.html和http://www.mail-archive.com/[email protected]/msg41845.html(但是這些都是8個月以上) – 2010-01-08 04:17:49

+1

邁克你是對的,他們曾經說過5.3會貶低短文標籤,但不再發布,他們會,我想我們會看到。 – danielrsmith 2010-01-08 04:26:57

0

請編輯php.ini文件

;short_open_tag = On 
with 
short_open_tag = On (just remove the ; and restart your apache server) 

現在將工作