开发者

Is it possible to concatenate heredoc string in PHP..?

开发者 https://www.devze.com 2023-01-21 19:00 出处:网络
With normal PHP string you can do this: $str = \"Hello \"; $str .= \"world\"; $str .= \"bla bla bla\"; $str .= \"bla bla bla...\";

With normal PHP string you can do this:

$str = "Hello ";
$str .= "world";
$str .= "bla bla bla";
$str .= "bla bla bla...";

But can you do the same with heredoc string..?

$str = <<<EOD
Hello 
world开发者_如何学C
EOD;

$str .= <<<EOD
bla bla bla";
bla bla bla...";
EOD;


Of course. Why wouldn't you be able to?

Heredocs evaluate to a string, so this is perfectly acceptable.


Yes you can. Heredoc is part of expressions, so you can even do this:

$s = 'abc' . <<<EOD
def
EOD
. 'ghi';

Be careful with the end-of-data marker though: it should be the only thing on a line.


Yes you can.

A heredoc is equivalent to double quoted string without the double quotes.

0

精彩评论

暂无评论...
验证码 换一张
取 消