Home > Backend Development > PHP Tutorial > How to use heredoc in php

How to use heredoc in php

不言
Release: 2023-04-02 21:50:02
Original
1658 people have browsed it

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;
?>
Copy after login

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"
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template