Heredoc and Nowdoc

Source: Internet
Author: User
Tags cloud hosting

Heredoc and Nowdoc
Many times using PHP nowdoc HereDoc inserting a lot of HMTL did not succeed, the same hint of grammar problems, in fact, the PHP manual is written in this way, it is very strange

Finally found the problem, originally this kind of document at the end, must be close to the first bit of the line, that is, EOF front can not have spaces, and for the code indentation, just produced such a problem.

Copy the code code as follows:
$str = <<< ' EOD '
Example of String
Spanning multiple lines
Using Nowdoc syntax.
Eod;//eod must be close to the front, must not have spaces, and do not miss the Terminator semicolon, and this end of the EOD do not add any symbols, whether it is Heredoc or Nowdoc

attached: The difference between Heredoc and Nowdoc

Heredoc uses <<< EOT identifiers, and Nowdoc uses identifiers such as <<< ' EOT ', Nowdoc is a new technology introduced by PHP5.3, it contains heredoc syntax, but the content of which is absolutely no escape and interpretation, what content is what content, will not parse PHP related content
PHP variables in Heredoc are recommended to be enclosed in {$name->change ()} braces, which avoids some ambiguity, and if you want to use the legendary escape character \, the escape character itself can be output using an escape character, that is, the representation method, These need to be escaped out of the curly braces.
To ensure that it is indeed available, it is recommended to use Heredoc syntax, which itself is also escaped, because PHP5.3 introduced the Nowdoc syntax, many cloud hosting bad environment will probably not support the cause of the rest of the dish.
Finally, Heredoc is introduced from PHP4.0, and Nowdoc syntax requires 5.3, because Heredoc contains nowdoc functionality, so it is better to use Heredoc for personal advice.

In simple terms:
1, Heredoc is dynamic nowdoc is static
2, heredoc similar to multiple lines of double quotes newdoc similar to multiple lines of single quotation marks
3, Heredoc is a kind of general processing scheme that deals with large-segment string, and Nowdoc is the "high-efficiency" static version of PHP to make up the efficiency problem of "heredoc" in the dynamic implementation.

Heredoc and Nowdoc

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.