'<?=' 在 PHP 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2020445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does '<?=' mean in PHP?
提问by user198729
<?php
$a=1;
?>
<?=$a;?>
What does <?=mean exactly?
究竟<?=是什么意思?
回答by BalusC
回答by Will Vousden
It's a shorthand for this:
这是一个简写:
<?php echo $a; ?>
They're called short tags; see example #2 in the documentation.
它们被称为短标签;请参阅文档中的示例 #2 。
回答by Gordon
Since it wouldn't add any value to repeat that it means echo, I thought you'd like to see what means in PHP exactly:
因为它不会添加任何值来重复它的意思echo,我想你想看看在 PHP 中到底是什么意思:
Array
(
[0] => Array
(
[0] => 368 // T_OPEN_TAG_WITH_ECHO
[1] => <?=
[2] => 1
)
[1] => Array
(
[0] => 309 // T_VARIABLE
[1] => $a
[2] => 1
)
[2] => ; // UNKNOWN (because it is optional (ignored))
[3] => Array
(
[0] => 369 // T_CLOSE_TAG
[1] => ?>
[2] => 1
)
)
You can use this code to test it yourself:
您可以使用此代码自行测试:
$tokens = token_get_all('<?=$a;?>');
print_r($tokens);
foreach($tokens as $token){
echo token_name((int) $token[0]), PHP_EOL;
}
From the List of Parser Tokens, here is what T_OPEN_TAG_WITH_ECHO links to.
回答by Jeffrey Aylesworth
<?= $a ?>is the same as <? echo $a; ?>, just shorthand for convenience.
<?= $a ?>与 相同<? echo $a; ?>,只是为了方便起见。
回答by Gaius Gracchus
As of PHP 5.4.0,
<?= ?>are always available even without the short_open_tag set in php.ini.
从 PHP 5.4.0 开始,<?= ?>即使没有在 php.ini 中设置 short_open_tag ,
也始终可用。
Furthermore, as of PHP 7.0, The ASP tags:
<%, %>and the script tag
<script language="php">are removed from PHP.
此外,从 PHP 7.0 开始,ASP 标签:
<%, %>和脚本标签
<script language="php">已从 PHP 中删除。
回答by Inspire
<?=$a; ?>
is a shortcut for:
是一个快捷方式:
<?php echo $a; ?>
回答by Matteo Riva
It's a shortcut for <?php echo $a; ?>if short_open_tags are enabled. Ref: http://php.net/manual/en/ini.core.php
这是启用<?php echo $a; ?>ifshort_open_tag的快捷方式。参考:http: //php.net/manual/en/ini.core.php
回答by antihero
I hope it doesn't get deprecated. While writing <? blah code ?>is fairly unnecessary and confusable with XHTML, <?=isn't, for obvious reasons. Unfortunately I don't use it, because short_open_tag seems to be disabled more and more.
我希望它不会被弃用。虽然编写<? blah code ?>与 XHTML 相当不必要且容易混淆<?=,但出于显而易见的原因,它并非如此。不幸的是我不使用它,因为 short_open_tag 似乎越来越被禁用。
Update:I do use <?=again now, because it is enabled by default with PHP 5.4.0.
See http://php.net/manual/en/language.basic-syntax.phptags.php
更新:我现在<?=再次使用,因为它在 PHP 5.4.0 中默认启用。见http://php.net/manual/en/language.basic-syntax.phptags.php

