0

Is there anything in HTML like heredoc syntax in PHP? Because in case of a span with long text I have to use br tags each time I want to have a linebreak.

  • use a div with fixed width, which'd cause the text to wrap itself. Heredocs do not "wrap" text for you. They're simply a way of outputting (or assigning) multiple lines of text without having to do repeated string concatenation. – Marc B Jul 11 '13 at 14:43
  • Use `

    ` elements, and allow the browser to wrap the text inside some containing element. Or is that too easy?

    –  Jul 11 '13 at 14:45

2 Answers2

2

Don't use spans with long text, use paragraphs, or parse your text as if it were Markdown, like here:

Some Line

Some Other Line

will render to:

<p>Some Line</p>
<p>Some Other Line</p>
moonwave99
  • 21,957
  • 3
  • 43
  • 64
1

The <pre> tag sounds like what you're looking for. From MDN: Whitespaces inside this element are displayed as typed.

<pre>
Hello
 !!!
World
</pre>

becomes

Hello
 !!!
World

You can also use the white-space CSS property to achieve a similar effect on any tag, though it behaves slightly differently.

<span style="white-space:pre;">Hello
 !!!
World
</span>
terite
  • 121
  • 3