PHP模板中的换行奇怪

mat*_*ndr 1 php templates

多年来我一直在处理这个问题,但是我从来没有调查过它.但我一直在想.

在PHP模板中,如果我运行这个:

<p>
<?php echo 'Between "?>" and "</p>" is one linebreak.'; ?>
</p>

<p>
<?php echo 'Between "?>" and "</p>" is one space, then one linebreak.'; ?> 
</p>

<p>
<?php echo 'Between "?>" and "</p>" is two linebreaks.'; ?>

</p>
Run Code Online (Sandbox Code Playgroud)

这是输出:

<p>
Between "?>" and "</p>" is one linebreak.</p>

<p>
Between "?>" and "</p>" is one space, then one linebreak. 
</p>

<p>
Between "?>" and "</p>" is two linebreaks.
</p>
Run Code Online (Sandbox Code Playgroud)

我不明白这种行为.为什么忽略单个换行符就好像它不在那里(如第一个例子中那样)?

tho*_*ter 5

如果它在关闭后立即出现,则PHP解释器会忽略换行符?>.这是为了与文本编辑器兼容,文本编辑器始终在文件的最后一行添加换行符.

这里这里在PHP手册中简要提到了这一点.

如果在换行符之前有一个空格,那么它就像正常一样输出,只有在换行之后它才会忽略它.