PHP 语法“=”是什么?
阅读一些 PHP 代码,我无法理解以下内容的用法:
我理解 php 标签的用法:
和
我正在阅读的确切用法是:
hidden('mode',$mode); ?>
其中 $form 是对象的新实例化类并“隐藏”了一个类方法。所有这些都可以理解,但是当我在 ? 之间放置一个空格时?和 = 我收到错误:
Parse error: syntax error, unexpected '=' in /home/...
我无法在 google 或 php.net 上找到有关语法的任何内容。
任何帮助将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这是
echo
的快捷方式。像这样的东西(其中expr
是任何表达式):在功能上等同于:
不建议使用此语法,因为它在某些服务器上未启用。 (如果有人使用共享主机,他们也可能无法重新启用它)
它的 PHP 文档是 此处。
It's a shortcut for
echo
. Something like this (whereexpr
is any expression):is functionally equivalent to this:
It's not recommended to use this syntax as it's not enabled on some servers. (and if someone is using shared hosting, they may not be able to re-enable it, either)
The PHP documentation on it is here.
是
的简写。不再推荐使用它,显然是因为解析器存在一些歧义或与某些 PHP 版本不兼容,尽管我仍然在像 Drupal 这样的大型项目中看到它。
编辑:它们被称为“短标签”,关于是否应该使用它们的讨论可以在这里找到:PHP 短标签可以使用吗?
<?=
is shorthand for<?php echo
. Its usage isn't recommended any more, apparently because of some ambiguity with the parser or incompatibility with some PHP versions, though I still see it in big projects like Drupal.Edit: They're called "short tags" and a discussion on whether they should be used or not can be found here: Are PHP short tags acceptable to use?
简而言之,“短开放标签”简直就是地狱。如果您的 php.ini / httpd.conf / .htaccess 中启用了 Short_open_tags,并且您尝试将 XML 标记放入您的文档中,就像这样...
PHP 会认为您尝试编写一些 PHP,然后出错,然后死掉。你最终不得不做
"Short open tags" are hell, in short. If you have short_open_tags on in your php.ini / httpd.conf / .htaccess and you try to put an XML tag into your document, like so...
PHP will think you tried to write some PHP, error, and die. You end up having to do
它称为短开放标记。如果您的服务器上启用了它,那么您就可以使用它。
来自 PHP 手册:
使用这些类型的标签可以让您收到与使用
echo
相同的结果。以下示例是等效的。示例:
It is called the short open tag. If it is enabled on your server, then you may use it.
From PHP Manual:
The use of these type of tags allow you to receive the same result as using
echo
. The following examples are equivalent.Example:
,当启用
short_tags
时,是的简写。
在 PHP 手册的开头对此进行了介绍。
<?=
, whenshort_tags
is enabled, is a shorthand for<?php echo
.This is covered right at the start of the PHP manual.
例如,当您在 HTML 文件中时,只是快速打印内容的简写。不建议使用它,因为它已被弃用。
Just a shorthand to quickly print content when, for example, you are in an HTML file. Its usage is not recommended since it is deprecated.
>是 的简写
http://mattsblog.ca/2007/07/ 26/每日提示-php-shorthand/
<?=stuff here;?> is a shorthand of <?php echo stuff here;?>
http://mattsblog.ca/2007/07/26/tip-of-the-day-php-shorthand/
这是一个短标签,并非可在所有服务器上使用。
与
相同
在
中放置空格会使短标签无效,这就是为什么你得到你的错误。
That is a short tag and is not available for use on all servers.
<?=
is the same as<?php echo
Putting a space in
<?=
invalidates the short tag which is why you get your error.