Home > Article > Backend Development > How to use heredoc in php
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 = 'world测试'; echo <<<EOT <html> <head> <meta charset="utf-8" /> <title>Test</title> </head> <body> Hello,$name! </body> </html> EOT; ?>
1. Start with the <<
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:
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!