-3

I have seen this through out several php file, and wanted to know, what purpose this served, if any and is it something i should use, or stay away from.

$html = <<<END
Some html stuff to output {$phpvariable
END;

vs.

$html = "Some html stuff to output {$phpvariable}";

1 Answers1

0

It's often used when you need a string with multiple lines.

For example you can use:

$html = <<<END
this is
a multiline
string
END;

Instead of:

$html = "this is\na multiline\nstring";

In addition, "END" in this case is the end of the string. You can use other word for it. (e.g. EOS -for End Of String).

Have a look to the php documentation: http://www.php.net/manual/en/language.types.string.php

S. A.
  • 3,714
  • 2
  • 20
  • 31
  • 1
    multiple lines is not the primary advantage of heredoc syntax –  Jan 26 '14 at 23:38
  • @Dagon So what's the primary advantage? Apart of multiline strings and avoid escaping double quotes I don't find any reason to use it. – S. A. Jan 27 '14 at 00:48