Home  >  Article  >  Backend Development  >  PHP about the usage of <<<

PHP about the usage of <<<

WBOY
WBOYOriginal
2016-07-25 08:46:451127browse
YUN77.NET Hong Kong server free trial welcome to visit~~~

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.
As follows:
$name = 'Shallow water swimming';
print <<


Untitled Document



Hello, $name!


EOT;
?>
1. Start with the << 2. Variables located 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:
$v=2;
$a= << "abc"$v
"123"
EOF;
echo $a; //The result is output together with double quotes: "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 homepage. There are two ways to write it. Obviously the second way of writing is simpler and easier to read.
function outputhtml(){
echo "";
echo "Homepage";
echo "Homepage content";
echo ";
}
function outputhtml()
{
echo <<
Homepage
Homepage content

EOT;
}
outputhtml();


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn