Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Server Side Coding
General server-side coding

How do I use the HERE Document? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5303" title="Pages that link to How do I use the HERE Document?" rel="nofollow" >How do I use the HERE Document?\

A HERE Document is a Perl idea which is also used in PHP4+ and basically what it allows you to do is create a long string without having to worry about escaping it. Perl will not process anything in between the starting word and its matching ending word (they can be whatever you want as long as they are the same).

In Perl there must not be a space between the second left-angle bracket and the starting word, and the starting word must be followed immediately by a semicolon. The ending word must appear on a line by itself with no whitespace on either side -- except for a required newline immediately following it -- and no semicolon:

code:
$extra_javascript = <<HERE;

<div class="myClass">Normal strings would require that the quotes (")
or apostrophes (') would need escaping which in a long string would
be time consuming so we use a HERE document.</div>
HERE



PHP does things slightly differently (3 <, and the semicolon is move to the last line of the HERE):

code:
$extra_javascript = <<< HERE
<div class="myClass">Normal strings would require that the quotes (")
or apostrophes (') would need escaping which in a long string would
be time consuming so we use a HERE document.</div>
HERE;



-----------------------------
Relevant links:

How to use HERE documents in Perl

"Here document" output style

Enter the "Here Document"

PHP 4 Here-Document gotcha

Using Strings

print() - PHP manual

echo() - PHP manual

______________________
Emperor

(Added by: Emperor on Sat 21-Sep-2002)

(Edited by: Emperor on Sat 21-Sep-2002)

(Edited by: mrj on Sun 19-Jan-2003)

(Edited by: Emperor on Mon 29-Sep-2003)

« BackwardsOnwards »

Show Forum Drop Down Menu