Here-docs (<<<) in PHP

By: Emiley J. Printer Friendly Format    


Here-docs enable you to embed large pieces of text in your scripts, which may include lots of double quotes and single quotes, without having to constantly escape them.

The following is an example of a here-doc:

<<<THE_END

PHP stands for "PHP: Hypertext Preprocessor".

The acronym "PHP" is therefore, usually referred to as a recursive acronym because the long form contains the acronym itself.

As this text is being written in a here-doc there is no need to escape the double quotes.

THE_END

The strings starts with <<<, followed by a string that you know doesn’t appear in your text. It is terminated by writing that string at the beginning of a line, followed by an optional semicolon (;), and then a required newline (\n). Escaping and variable substitution in here-docs is identical to double-quoted strings except that you are not required to escape double quotes.



Ask a Question



Most Viewed Articles (in PHP )

Latest Articles (in PHP)

Comment on this tutorial