How to use a here document in PHP

PHP here document FAQ: How do I create a here document in PHP?

If you ever need to use a "here document" in PHP, here's a short example of the PHP here document syntax:


print <<< END
Four score and seven years ago
our fathers set onto this continent
(and so on ...)


I believe the closing tag you use ("END" in my case) must begin in the first column. This is typical with here document syntax, but I haven't tested it in PHP.

It may help to see this in more of a PHP or HTML context, and to that end, here is a second PHP here document example, with this one looking much more like something you'd use in a real PHP program:


function print_footer()
  print <<< END_OF_BLOB
<div id ="footer">
printed by alvin alexander,

# call the function somewhere later in your php script ...


As in other programming languages, the here document syntax in PHP is very useful for when you want to display large chunks of text, and don't want (or need) to go through the trouble of creating strings to represent that blob of text.

I hope these PHP here document examples are helpful.