Whether to add terminator to php file

王林
Release: 2023-02-24 11:26:02
Original
3210 people have browsed it

Whether to add terminator to php file

When PHP includes a file a.php, if a.php has extra characters (including carriage returns or spaces) after the PHP end tag, it will be included simultaneously. is output.

Example:

##a.php

<?php
// anycode here
?>
[回车]
[回车]
Copy after login

b.php

<?php
ob_start();
//include_once &#39;PHPSn.class.php&#39;;
include_once &#39;a.php&#39;;
$con = ob_get_contents();
ob_clean();
var_dump($con);
?>
Copy after login

Output result:

 string(2) "
"
Copy after login

Perhaps in general development, you will not find any impact this will have, but when your PHP program is a download The script reads a file through readfile. At this time, the file downloaded through the php script has been changed. Use UE to use binary encoding and find that there is an extra 0D0A0D0A in front of it. This is why.

If the file content is pure PHP code, it is best to remove the PHP closing tag at the end of the file. This prevents PHP from accidentally adding spaces or newlines after the closing tag, causing PHP to start outputting these spaces when there is no intention to output them in the script.

Recommended tutorial:

PHP video tutorial

The above is the detailed content of Whether to add terminator to php file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template