Triple quoted strings

jeff.ecmascript at jeff.ecmascript at
Wed Mar 5 15:44:02 PST 2008

If I understand the motivation for triple quoted strings, it's to allow 
multiline strings with inverted commas and quotes within them, and to 
allow quotes and inverted commas within those substrings, all without 
requiring a continuation marker.

PHP has a structure that's used for this sort of thing, which works 
quite well and is used when you have a large block of text tobe used as 
a string. As an example of when this is used, commonly, emails that are 
constructed in code use this technique.

The heredoc syntax is:

$var = <<<EndOfStringMarker
This text is part of the string. It can include " and '. It can include 
references to one or more $variable, each of which is replaced with the 
value of the variable. This string includes the
line breaks without needing backslash syntax like backslash n to 
introduce a newline. Consequently the previous sentence includes a break 
after the fourth word.
To end this string you must have whatever end of string marker you have 
chosen on a line by itself. Thusly...

PHP documentation on the feature is at

IMO this is a useful but fairly infrequently used language facility. 
Constructing large blocks of text without this facility would be harder, 
but losing the facility would not be a major blow.

Jeff Veit

More information about the Es4-discuss mailing list