2010-01-08 55 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) 

现在将工作