Heredoc

Heredoc is a robust way to create string in PHP with more lines but without using quotations. Heredoc is rarely used as the day by day usage is more complicated as creating strings with quotes or double quotes. Besides this the not properly used heredoc can lead to problems in your code.

• Delimits strings without using quotes (so no need to escape)
• Start with <<< and an identifier; end with same identifier
• Do not indent ending identifier or add any chars

Example

<?php
 $str = <<<DEMO
 phpcode
 DEMO;
 print $str;
 ?>

Output

phpcode

Share