By: Emiley J. Emailed: 1728 times Printed: 2328 times
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:
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 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.
Be the first one to add a comment
Most Viewed Articles (in PHP )
Most Emailed Articles (in PHP)