This article provides a detailed analysis of the use of heredoc in php. if you need a friend, refer to Heredoc technology. in the formal PHP documents and technical books, it is generally not detailed, I just mentioned that this is a Perl-style string output technology. However, the heredoc technology is cleverly used in some forum procedures and some article systems to partially implement the quasi-separation of interfaces and codes. the phpwind template is a typical example.
As follows:
The code is as follows:
$ Name = 'shappgame ';
Print <
Untitled Document
Hello, $ name!
EOT;
?>
1.
< < span><>Start to mark start,
EndEnd mark ends,
The end mark must be written at the top, and there cannot be indentation or spaces,There must be 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:
The code is as follows:
$ V = 2;
$ A = <
"Abc" $ v
"123"
EOF;
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.
The code is as follows:
Function outputhtml (){
Echo"";
Echo"Home Page";
Echo"Homepage content";
Echo";
}
Function outputhtml ()
{
Echo <
Home Page
Homepage content
EOT;
}
Outputhtml ();