为什么有些 php 文件不以右括号“?"结尾? [英] why some php files do not end with the closing bracket "?>"?

查看:38
本文介绍了为什么有些 php 文件不以右括号“?"结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Wordpress 和其他 CMS,我注意到某些 php 文件没有结束 ?>.

I have been working with Wordpress and other CMS and I have noticed that some of the php files do not have a closing ?>.

当我编写自己的文件时,必须包含?>,否则软件会崩溃.我想知道他们是如何使它工作的,或者是否有接受这种类型的 php 文件的主题的特定部分.也许右括号 ?> 嵌入在我没有见过的不同文件中.

When I write my own files, I have to include the ?>, otherwise the software crashes. I'm wondering how they make it work, or if there are specific sections of a theme that accept this type of php files. Maybe the closing bracket ?> is embedded in a different file that I haven't seen.

有没有人解释一下?

如果我决定将 ?> 放在这些文件上,系统会崩溃吗?或者我可以安全地用右括号写它们?

If I decide to put the ?> on these files, will the system crash? or I can safely write them with the closing bracket?

推荐答案

来自 PHP 官方文档:

From the official PHP documentation:

如果文件是纯 PHP 代码,最好省略 PHP 结束符文件末尾的标签.这可以防止意外的空格或新的在 PHP 结束标记之后添加的行,这可能会导致不需要的效果,因为 PHP 将在没有时开始输出缓冲程序员的意图是在该点发送任何输出脚本.

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

http://php.net/manual/en/language.basic-syntax.phptags.php

这篇关于为什么有些 php 文件不以右括号“?"结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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