I'm new to PHP and don't understand what the point of <<<_END
is. Could someone please explain when this should be used? I've looked at various examples and they all seem to have HTML embedded within them. But I can use HTML without the <<<_END
tags, so why should I use them? I tried searching the manual, but I keep finding the end()
method for arrays.

- 3,983
- 11
- 46
- 73
-
Please show the code in question. You are probably looking for "heredoc notation" – Pekka Jan 13 '11 at 01:07
-
I've seen it in various places, but here's a link to one example http://lpmj.net/examples.php?c=20&e=5&x=php – Skoder Jan 13 '11 at 01:09
-
Funny thing I use PHP for more than 5 years now and I never knew this exists. – Ákos Nikházy Feb 11 '15 at 13:27
5 Answers
It's the start of a heredoc. you can do:
$data = <<< _END
You can write anything you want in between the start and end
_END;
_END
can be just about anything. You could put EOF
or STUFF
. as long as you use the same thing at the start and the finish.

- 38,725
- 6
- 68
- 74
-
Thanks. So the only reason you'd use heredocs would be to write multiple lines (for clarity)? – Skoder Jan 13 '11 at 01:11
-
It is also useful for writing large strings of text without the need to escape any characters. – Mitch Dempsey Jan 13 '11 at 01:12
-
-
Heredocs are basically multi-line double-quoted strings, without the need for the quotes. – Marc B Jan 13 '11 at 03:11
This signifies the beginning of a heredoc (a multi-line string that allows you to use quotation marks in the middle, unescaped) that ends when you encounter the _END
It can be useful to define HTML in one of these if the goal is to assign it to a variable or pass it to a function rather than printing it to the web server immediately.

- 57,498
- 14
- 111
- 168
That syntax is called heredoc
<<<_END
some text
_END
Basically, it's a way of writing a string without worrying about escaping quotes and so on.
As you've mentioned, it doesn't really provide a lot of benefit over other string formats - although, it does mean you can write a block of HTML without escaping out of PHP with ?>
It also isn't too popular as its use generally goes against the practice of seperating content from logic by embedding the content in the middle of your script.

- 8,375
- 10
- 51
- 92
Does this help? http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
It allows you to echo out a block of text (just the same as with echo "words";
), but without using the beginning/ending quotes, and without having to escape contained double quotes. Read the manual link above for more detail.

- 11,056
- 3
- 42
- 65