I am implementing node to PDF using Drupal and tcpdf. In such case I am suppose to use this <<<EOD
tag. If I don't use it, it throws error. I can't exactly get the purpose of <<<EOD
.
Could anybody please explain the concept of this?
$html = <<<EOD <tr> <td>TEST</td> </tr> EOD;
EOD = End Of Data, EOT = End of Text.
Heredoc and nowdoc provide useful alternatives to defining strings in PHP to the more widely used quoted string syntax. They are especially useful when we need to define a string that spans multiple lines (new lines are also interpreted when used in quoted strings) and where use of whitespace is important.
A heredoc is a way to define a multiline string, while maintaining the original indentation & formatting. You can use a Heredoc to embed snippets of SQL, HTML, or even XML code. A Heredoc starts with <<- , followed by a word that represents the name for the heredoc, then the contents.
Heredoc's are a great alternative to quoted strings because of increased readability and maintainability. You don't have to escape quotes and (good) IDEs or text editors will use the proper syntax highlighting.
That is not HTML, but PHP. It is called the HEREDOC string method, and is an alternative to using quotes for writing multiline strings.
The HTML in your example will be:
<tr> <td>TEST</td> </tr>
Read the PHP documentation that explains it.
there are four types of strings available in php. They are single quotes ('), double quotes (") and Nowdoc (<<<'EOD')
and heredoc(<<<EOD)
strings
you can use both single quotes and double quotes inside heredoc string. Variables will be expanded just as double quotes.
nowdoc strings will not expand variables just like single quotes.
ref: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With