This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
这是根据官方文档的信息:
可以在PHP中使用四对不同的开始和结束标记.其中两个,
<?php ?>并且<script language="php"> </script>始终可用.另外两个是短标签和ASP样式标签,可以从php.ini配置文件打开和关闭.因此,虽然有些人发现短标签和ASP样式标签很方便,但它们的便携性较差,一般不推荐.
在我的经验,大多数服务器都启用短标记.打字
<?=
Run Code Online (Sandbox Code Playgroud)
打字要方便得多
<?php echo
Run Code Online (Sandbox Code Playgroud)
程序员的便利是一个重要因素,为什么不推荐他们?
有人可以向我解释何时<?=需要使用或者为什么这个程序员会这样编码?我正在为SPBAS创建第三方模块,我差不多想出来了,我只是不知道我指定的两个不同选项的重要性.
提前致谢.
在我发现的一些编码中,我看到作者使用<?=并?>在他的代码中.我想知道这是不是一些花哨的PHP或其他语言.我很想知道答案,因为我很想学习这段代码.我相信它可能是Fuel PHP框架,但我不确定,因为它没有文档.谢谢.
它的一个例子是:
<?=SITEROOT?>
Run Code Online (Sandbox Code Playgroud)