为什么速记的PHP开放语句不起作用? [英] why would shorthand PHP opening statements not be working?

查看:78
本文介绍了为什么速记的PHP开放语句不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Mac设置为php服务器,但是,到目前为止,我取得了成功,但似乎有点麻烦.

I am trying to get my Mac setup as a php server, however, as successful as I have been so far, I seem to have run into a bit of bother.

我的PHP开头语句不起作用...而只是速记符.

My PHP opening statments are not working... but only the shorthand ones.

这有效:

<?php 
  phpinfo();
?>

这不是:

<?
  phpinfo();
?>

是Mac 10.5.希望有人能帮忙.

It's Mac 10.5. Hope that someone can help.

谢谢

推荐答案

在您的php.ini中,设置

In your php.ini, set short_open_tag to On.

short_open_tag = On

从文档中

short_open_tag布尔值

short_open_tag boolean

告诉是否缩写(<? ?>) PHP的open标签应该是 允许的.如果您想在其中使用PHP 与XML结合使用,您可以禁用 此选项以使用<?xml ?> 排队.否则,您可以打印它 使用PHP,例如:<?php echo '<?xml version="1.0"'; ?>.另外如果 禁用,您必须使用长格式 的PHP打开标记(<?php ?>).

Tells whether the short form (<? ?> ) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?> . Also if disabled, you must use the long form of the PHP open tag (<?php ?> ).

short_open_tag PHP_INI_ALL从5.3.0开始,这意味着它可以在任何地方更改(php.ini,.htaccess,在脚本中).它是5.3.0之前的PHP_INI_PERDIR,这意味着可以在php.ini和.htaccess中进行设置.因此,即使您不控制服务器,在大多数情况下也可以更改其值.

short_open_tag is PHP_INI_ALL as of 5.3.0, which means that it can be changed anywhere (php.ini, .htaccess, in script). And it was PHP_INI_PERDIR before 5.3.0, which means that it can be set in php.ini and .htaccess. Therefore, you can change its value in most cases even if you don't control the server.

但是,此设置默认为关闭.如果您要分发脚本,则该脚本在大多数开箱即用的安装中均无法使用.在这种情况下,搜索/替换以切换到<?php是个好主意.

However, this setting is off by default. If you are going to distribute your script, it won't work on most installations out of the box. In this case, a search/replace to switch to <?php is a good idea.

这篇关于为什么速记的PHP开放语句不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆