参见英文答案 > Why would one omit the close tag? 14个
我有一个PHP结束标记的有趣现象.我有一个由Ajax调用执行的php文件.在php文件中包含了一个具有各种功能的php库文件.当这个库被包含时,php响应包括一堆空行.当我从库中删除结束标记时,这种情况就停止了.
任何人都可以向我解释这里发生了什么?
解决方法:
这是有据可查的.从PHP Manual:
The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.
省略结束标记有助于防止意外的空格或换行符添加到文件末尾.