Home >Backend Development >PHP Problem >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 ?> [回车] [回车]
b.php
<?php ob_start(); //include_once 'PHPSn.class.php'; include_once 'a.php'; $con = ob_get_contents(); ob_clean(); var_dump($con); ?>
Output result:
string(2) " "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:
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!