tags:

views:

70

answers:

3

I know I shouldn't be outputting things directly in PHP, but using a template instead, but whatever.

I remember perl being able to do this, and as I reached for my perl book, I realized: I already packed it, as I'm moving. It's incredibly difficult to search for "<<<", as well.

So, I know I can go,

echo <<<SOMESTUFF
blah
blah
blah

but other than that I'm at a loss... How do I end it? Where do I need semicolons?

+3  A: 

In PHP, this syntax is called a heredoc. The linked documentation contains some helpful examples.

Greg Hewgill
A: 

To end it, type:

echo <<<SOMESTUFF
...
SOMESTUFF

With SOMESTUFF being on a line of its own. See the PHP manual on "heredocs" for more info.

Lucas Jones
A: 

This is called Heredoc syntax, and allows you to define long strings, without having to care about escaping double-quotes (nor single, btw)

Syntax goes like this :

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

Note this (quoting the doc) :

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

And also note it is not exactly the same as nowdoc syntax, which only exists since PHP >= 5.3

Pascal MARTIN