How to Use heredoc in php

Source: Internet
Author: User

Heredoc technology is generally not detailed in regular PHP documents and technical books. It only mentions that it is a Perl-style string output technology. However, some forum programs and some article systems use heredoc to partially implement the quasi-separation of interfaces and codes. phpwind template is a typical example.

As follows:
<? Php
$ Name = shappend games;
Print <EOT

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Untitled Document </title>
<! -- 12321 -->
Hello,$ Name!


1.<EndStart to start, End with End to End,The end mark must be written at the top, with no indentation or spaces, and a semicolon at the end of the end mark.. The start tag is the same as the start tag, for example, EOT, EOD, and EOF in uppercase.The start and end tags do not appear in the body..

2. Variables between the start tag and the end tag can be parsed normally,But the function cannot.. In heredoc, variables do not need to be concatenated with connectors. Or, as shown below:

$ V = 2;
$ A = <EOF
"Abc"$ V
Echo $ a; // The result is output together with double quotation marks: "abc" 2 "123"

3. heredoc is often used to output a large number of HTML syntax d documents. For example, the outputhtml () function outputs the HTML homepage. There can be two writing methods. Obviously, the second method is relatively simple and easy to read.

Function outputhtml (){
Echo "Echo "Echo "<body> homepage content </body> ";
Echo "}

Function outputhtml ()
Echo <EOT
<Head> <title> Home page </title> <Body> homepage content </body>

Outputhtml ();

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: 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.