A point to note in PHP Nowdoc and Heredoc use

Source: Internet
Author: User
Tags cloud hosting

Many times the use of PHP nowdoc HereDoc insert a lot of HMTL did not succeed, the same hint syntax problems, in fact, PHP manual notes that is written, it is very strange

Finally found the problem, the original document at the end, must be close to the first line, that is, EOF front can not have spaces, and in order to code indentation, just created such a problem. The code is as follows: $str = <<< ' EOD ' Example of string spanning multiple lines using Nowdoc syntax.   Eod;//eod must be close to the front, can not have spaces, while not missing the end of the semicolon; Attached: The difference between Heredoc and Nowdoc Heredoc using the <<< EOT identifier, and Nowdoc using the <<< ' EOT ' as a marker, Nowdoc is the introduction of PHP5.3 new technology, it contains the Heredoc syntax, but the content will not be any escape and interpretation, what content is what content, will not parse PHP-related content heredoc PHP variables recommended use {$name- The >change ()} braces are enclosed so that you can avoid ambiguity, and if you want to output the legend's escape character, the escape character itself can be exported using the escape character, which means that this notation, such as braces, needs to escape the output. In order to ensure that it is available, it is recommended that the syntax of Heredoc be used with escape, because the Nowdoc syntax introduced by PHP5.3, many cloud hosting environments may not support the cause of the leftovers.   Finally, the Heredoc is introduced from the PHP4.0, and Nowdoc syntax requires 5.3 version, because the Heredoc contains Nowdoc function, so personal advice or use heredoc better. In simple terms: 1, Heredoc is a dynamic nowdoc is a static 2, heredoc similar double quotes newdoc similar to multiple lines of single quotes 3, Heredoc is a special processing of large segments of the string, and Nowdoc is a general-purpose processing scheme, and is PHP to make up for the dynamic implementation of " Heredoc "Efficient" static version of "Efficiency issues"

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.