为什么简写 PHP 开头语句不起作用?

发布于 2024-07-22 07:05:59 字数 282 浏览 4 评论 0原文

我正在尝试将我的 Mac 设置为 php 服务器,但是,尽管到目前为止我已经取得了成功,但我似乎遇到了一些麻烦。

我的 PHP 开头语句不起作用...但只有速记语句。

这有效:

<?php 
  phpinfo();
?>

这不行:

<?
  phpinfo();
?>

这是 Mac 10.5。 希望有人可以提供帮助。

谢谢

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.

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

This works:

<?php 
  phpinfo();
?>

This doesn't:

<?
  phpinfo();
?>

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丘比特射中我 2024-07-29 07:05:59

在 php.ini 中,设置 short_open_tag 至开。

short_open_tag = On

来自文档:

short_open_tag 布尔值

告诉是否是缩写形式 ( )
PHP 的开放标签应该是
允许。 如果你想使用 PHP
与 XML 结合,您可以禁用
此选项以便使用
排队。 否则,您可以打印它
对于 PHP,例如: 。 还如果
已禁用,您必须使用长格式
PHP 开放标记 ( )。

编辑:

short_open_tagPHP_INI_ALL 自 5.3.0 起< /a>,这意味着它可以在任何地方更改(php.ini、.htaccess、脚本中)。 而5.3.0之前是PHP_INI_PERDIR,也就是说可以在php.ini和.htaccess中设置。 因此,即使您不控制服务器,在大多数情况下您也可以更改其值。

但是,此设置默认处于关闭状态。 如果您要分发脚本,则它无法在大多数开箱即用的安装中运行。 在这种情况下,搜索/替换切换到 是一个好主意。

In your php.ini, set short_open_tag to On.

short_open_tag = On

From the docs:

short_open_tag boolean

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 ?> ).

Edit:

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.

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.

红衣飘飘貌似仙 2024-07-29 07:05:59

检查您的 php.ini 文件是否包含 short_open_tag=1< /a> 行。

Check if your php.ini file contains the short_open_tag=1 line.

巷子口的你 2024-07-29 07:05:59

您是否验证了 short_open_tag(请参阅此处) 在你的 php.ini 中启用了吗?

Did you verify that short_open_tag (see here) is enabled in your php.ini?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文