You can use the <<< sequence like this (this is called a Heredoc string):

$HtmlOutput = <<<_END
  <form method="GET">
    <div>Search Term: <input type="search" id="q" name="q"></div>
    <div>Max Results: <input type="number" id="maxResults" name="maxResults" min="1" max="50" step="1" value="25"></div>
    <input type="submit" value="Search">
  $HtmlOutput = "";
  $HtmlOutput .= <<<_END


The terminating marker must be at the start of a line and the only thing on the line (no comment or even whitespace after it!!!)

The advantage of this is that there is no need for line breaks, escape characters (\’ etc) – what is between the markers is output exactly as it appears but with any variable names evaluated.  _END can be anything.  You can also use &MyText <<< _END … to assign the contents to a variable instead of echoing.

You can include variables within the text. For complex variables you can enclose them in curley brackets like this:

blah blah {$foo->bar[1]} blah
Including a function call
${!${''} =(time())}

$HtmlOutput = <<<_END
  <p>Somthing ${!${''} =(time())} someting</p>

(This is based on the topic here and relies on this nifty parser hack)

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.