PHP equivalent to python's triple-quotes - How to print bulk / lots of HTML within PHP without escaping

Alex Spencer picture Alex Spencer · Dec 17, 2012 · Viewed 7.8k times · Source

Possible Duplicate:
php string escaping like python’s “”“ ”“”?

The triple-quotes in python escapes all quotes and newlines contained within. For example,

""" this
is all


just one string. I can even tell you "I like pi".
Notice that the single quotes are escaped - they don't end the string; and the newlines become part of the string
"""

Does anybody know if PHP has an equivalent to python's

""" <form><h1>PUT HTML HERE</h1> </form> """
enter code here

EDIT: For those looking at this question in the future, I have answered it, here is an example:

$heading = "Heading Gettizburgz"; print <<< END <p><h1>$heading</h1> "in quotes" 'in single' Four score and seven years ago<br/> our fathers set onto this continent<br/> (and so on ...)<br/> </p> END;

prints: Heading Gettizburgz "in quotes" 'in single' Four score and seven years ago our fathers set onto this continent (and so on ...)

Note one important thing, you must make sure that the very last END is to the far left (fist column) of your code without ANY spaces before it.

source: http://alvinalexander.com/blog/post/php/php-here-document-heredoc-syntax-examples

Answer

Michael Mior picture Michael Mior · Dec 17, 2012

You can use heredocs or nowdocs (see below heredocs).

Heredoc

$bar = <<<EOT
bar
EOT;

Nowdoc

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