Heredoc, in case you’ve never heard the term before, is an alternative way for encapsulating strings. It’s used and seen much less often than the standard single or double quotes, but it fulfills the same role. Heredoc is like putting peanut butter on bananas: you either grow up doing it or you don’t. The heredoc
method works just like a double quote in that the values of variables will be printed, but you can define your own delimiter, which is particularly nice when printing oodles of HTML (with its own double-quotation marks).
The only catch to heredoc is that its syntax is very particular!
The heredoc syntax starts with <<<, immediately followed by an identifier. The identifier is normally a word in all caps. It can only contain alphanumeric characters plus the underscore (no spaces), and it cannot begin with a number. There should be nothing on the same line after the initial identifier, not even a space! So usage of heredoc might begin like
echo <<
- Kiran's blog
- 652 reads













Post new comment