"; and finally delete the closing tag."/> "; and finally delete the closing tag.">

Home  >  Article  >  Backend Development  >  How to realize that php does not output empty lines

How to realize that php does not output empty lines

藏色散人
藏色散人Original
2021-06-16 09:38:551766browse

How to achieve non-outputting of blank lines in php: first check whether the file is imported through "get_included_files"; then check whether there is a closing tag "?>"; finally delete the closing tag.

How to realize that php does not output empty lines

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Is there a blank line in the final output of php? How to prevent php from outputting empty lines?

Encountered a problem, one more line was output when using php for output;

I thought it was a logical problem at first, but found nothing after checking;

But there is more output The blank line is output after all the logic is executed. It feels magical and is recorded here;

The example is as follows:

<?php
echo "1\n";
echo "2\n";
?>
1
2
3
4
5
6

The expected output should be

>>>>>><<<<<<<
1
2
>>>>>><<<<<<<

but the actual The output is

>>>>>><<<<<<<
1
2
>>>>>><<<<<<<

. The reason is because it was added at the end of php? >php closing tag.

In this case, the most common one is that a closing tag ?> is used at the bottom of a certain PHP file. In this case, a newline is entered after the closing tag ?>. In the source code, it is There is an extra blank line in front of the template. This is a kind of code irregularity. For pure PHP files, the specification prohibits adding closing tags at the end. That is, < ?php is filled with php code from beginning to end, without closing tags, so no matter how you add line breaks, it will be ignored.

This situation cannot be seen visually. You can get_included_files(); before outputting the template; and then check each file one by one to see which file has more closing tags

Recommended learning : "PHP Video Tutorial"

The above is the detailed content of How to realize that php does not output empty lines. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn