Heredoc technology is generally not described in detail in formal PHP documents and technical books. It is only mentioned that it is a Perl-style string output technology. However, some current forum programs and some article systems cleverly use heredoc technology to partially realize the quasi-separation of interface and code. The phpwind template is a typical example.
is as follows:
Copy code The code is as follows:
$name = 'Shallow Water Swimming';
print <<
Untitled Document
Hello,$name!
EOT;
?>
1. Start with
<< start tag, end with
End end tag,
end tag must be written at the beginning, There can be no indentation or spaces, and there must be a semicolon at the end of the closing tag. The start tag is the same as the start tag. For example, it is commonly represented by uppercase EOT, EOD, and EOF, but it is not limited to those few. Just make sure that the
start tag and end tag do not appear in the text .
2. Variables between the start tag and the end tag can be parsed normally, but functions cannot . In heredoc, variables do not need to be spliced with connectors. or,, as follows:
Copy the code The code is as follows:
$v=2;
$a= <<"abc"$v
"123"
EOF;
echo $a; //Result with double quotes Output together: "abc"2 "123"
3. heredoc is often used when outputting documents containing a large number of HTML syntax documents. For example: the function outputhtml() should output the HTML home page. There are two ways to write it. Obviously the second way of writing is simpler and easier to read.
Copy code The code is as follows:
function outputhtml(){
echo "";
echo "
Homepage";
echo "Homepage content";
echo " html>;
}
function outputhtml()
{
echo <<
Homepage Home page content
EOT;
}
outputhtml();
http://www.bkjia.com/PHPjc/327655.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327655.htmlTechArticleHeredoc technology is generally not described in detail in regular PHP documents and technical books, but is just mentioned. A Perl-style string output technique. But some of the current forum programs...