Why some php Code <? Php but not?> End?

Source: Internet
Author: User
Why some php codes include & amp; lt ;? Php but not? & Amp; gt; end? Why some php code has End?

Reply content:

Why some php code has End?

PHP-FIG/PSR-2: Code style Specification

LS writes are good. Let's say a few more words.

A. php:


  Is there a blank character?>

B. php:


  

A. the blank characters at the end of php will also be output, and an error will be reported, and N has not been found for a long time ~~ However?>This problem will not occur.

The lessons of blood and tears

PHP can not use it in a pure PHP file?> End.

This is to avoid errors caused by additional characters when the PHP file is contained.

If the script contains other scripts, what does it end with?> Do not write it to avoid errors.

I have read, the answer does not mention the PSR specification, the basic code specification of the PSR-1, the description of the beginning of the Code and the beginning of the PHP tag is as follows:

  1. Overview
    The PHP code file must start

2.1. PHP tag
PHP code is required Long tag or Short output tag;

And all the sample code from PSR-1 to 4 is useless?> For reference.

If the file content is pure PHP code, it is best to delete the PHP end mark at the end of the file. This avoids accidental addition of spaces or line breaks after the PHP end mark, which may cause PHP to start to output these spaces, but the script does not have the intention to output at this time.

Echo "Hello world ";

//... More code

Echo "Last statement ";

// The script ends now and no PHP end mark is displayed.

Generally, if a file is at the end of the file to be included, do not use?>End

It is to prevent meaningless output due to white spaces at the end, which affects header output! In addition, the PHP script does not have to end with it.

If there is no other code below PHP, can it be omitted?>

It's all about upstairs.
Pure PHP does not need to be written?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.