Home  >  Article  >  Backend Development  >  How to use heredoc in php

How to use heredoc in php

不言
不言Original
2018-07-09 17:48:281604browse

This article mainly introduces the usage of heredoc in PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to

Heredoc technology, which can be used in regular PHP documents and Technical books generally do not describe it in detail, but only mention that this is a Perl-style string output technology.
But 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.

<?php
$name = &#39;world测试&#39;;
echo <<<EOT
<html> 
<head> 
<meta charset="utf-8" /> 
<title>Test</title> 
</head> 
<body>
Hello,$name! 
</body> 
</html>
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 use connectors.
3.heredoc is often used when the output contains a large amount of HTML syntax and documents. For example:

<?php
$v = 123456;
$a = <<<EOF
"abc" $v "123"
EOF;
echo $a; 
// 结果连同双引号一起输出:"abc" 123456 "123"
?>

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Later static binding of PHP

##How to use PHP arrays

The above is the detailed content of How to use heredoc in php. For more information, please follow other related articles on the PHP Chinese website!

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