📅  最后修改于: 2023-12-03 15:15:30.691000             🧑  作者: Mango
In PHP, heredoc is a way to create strings that span multiple lines and contain variables without having to use concatenation.
The syntax for heredoc is as follows:
$text = <<<EOT
This is a heredoc string.
It can span multiple lines.
Variables can be included like this: $variable
EOT;
<<<
followed by an identifier (in this case, EOT
). The identifier can be any string, as long as it does not appear in the string content.$
.$name = "John Smith";
$title = "Software Developer";
$bio = <<<EOT
Name: $name
Title: $title
John is a software developer with 5 years of experience. He specializes in PHP and JavaScript.
In his free time, John enjoys hiking and playing guitar.
EOT;
echo $bio;
Output:
Name: John Smith
Title: Software Developer
John is a software developer with 5 years of experience. He specializes in PHP and JavaScript.
In his free time, John enjoys hiking and playing guitar.
Heredoc strings can make it easier to create strings that span multiple lines and contain variables. They are particularly useful for long strings with complex formatting.