Note the usage of nowdoc and heredoc in PHP _ php instance

Source: Internet
Author: User
Tags cloud hosting
Many times phpnowdocHereDoc is used to insert a large number of Hmtl, but it prompts a syntax error. In fact, the PHP manual indicates that the script is written in this way. it is really strange that the problem was found at the end, at the end of such a document, it must be near the first line, that is to say, there must be no space before the EOF, and for code indentation, this problem occurs.

The code is as follows:


$ Str = <'eod'
Example of string
Spanning multiple lines
Using nowdoc syntax.
EOD; // The EOD must be near the front, and there must be no spaces. do not miss the end character semicolon;



Appendix: differences between heredoc and nowdoc

Heredoc uses the <EOT identifier, while nowdoc uses the <'eot' identifier. nowdoc is a new technology introduced in PHP5.3 and contains the heredoc syntax, however, the content will never be converted or interpreted. what is the content and PHP-related content will not be parsed.
We recommend that you enclose the PHP variable {$ name-> change ()} in brackets in heredoc to avoid ambiguity. if you want to output the variable as is, you can use the legendary escape character \, escape characters can be output using escape characters, that is, the \ representation method. escape output is required for all the braces.
To ensure availability, we recommend that you use the heredoc syntax, which is also escaped. because the nowdoc syntax introduced by PHP5.3, it is very likely that it is not supported by the multi-cloud hosting environment, resulting in a break.
At last, heredoc was introduced from PHP4.0, while nowdoc requires version 5.3. because heredoc contains the nowdoc function, it is recommended that heredoc be used.

To put it simply:
1. heredoc is dynamic and nowdoc is static.
2. heredoc is similar to the double quotation marks of multiple rows. newdoc is similar to the single quotation marks of multiple rows.
3. heredoc is a general solution dedicated to processing large string segments, while nowdoc is a static version of php that achieves "high efficiency" to make up for the dynamic implementation of the "heredoc" efficiency problem.

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.