PHP结束标记“?" [英] PHP end tag "?>"

查看:74
本文介绍了PHP结束标记“?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的现象,带有PHP结束标记.我有一个通过Ajax调用执行的php文件.在php文件中包含具有各种功能的php库文件.当包含此库时,php响应中包含一堆空行.当我从库中删除结束标签时,这停止了. 谁能给我解释一下这是怎么回事?

I've had an interesting phenomenon with a PHP end tag. I had a php file that was executed by an Ajax call. In the php file was included a php library file with assorted functions. When this library was included the php response included a bunch of blank lines. When I removed the end tag from the library this stopped happening. Can anyone explain to me what going on here ?

推荐答案

有据可查.从 PHP手册:

文件末尾的PHP块的结束标记是可选的,并且在某些情况下,当使用include()或require()时,它会有所帮助,因此在文件末尾不会出现不需要的空格,并且您以后仍然可以将标头添加到响应中.如果您使用输出缓冲,并且不想在包含的文件生成的部分的末尾看到多余的空白,这也很方便.

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.

省略结束标记可帮助您防止意外的空格或换行符添加到文件末尾.

Omitting the closing tag helps you prevent accidental whitespace or newlines from being added to the end of the file.

这篇关于PHP结束标记“?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆