Heredoc syntax provides a means to delimit a string without using single or double quotes. This can be useful in situations with strings that contain many single or double quotes or that break across multiple lines.
In PHP, <<< (three left angle brackets) is the heredoc operator, denoting the beginning of the string. This operator is followed immediately by a custom identifier, which is then used to close the heredoc string. The closing identifier must begin in the first column of the line, containing no other characters except a semicolon (;). There can be no spaces/tabs after or before the identifier or the semicolon.
The following is an example of heredoc string usage:
$str = <<<EOF Example of string spanning multiple lines using heredoc syntax. EOF; print $str;
In Bash, a here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor. A limit string delineates (frames) the command list. The special symbol << designates the limit string. This has the effect of redirecting the output of a file into the stdin of the program or command.
The here document looks like this:
#!/bin/bash interactive-program <<LimitString command #1 command #2 ... LimitString
By default bash will interpolate the content of the block like it would in a double-quoted string. If you want to avoid this (for example if your here document contains a script you want to output verbatim) you can put single quotes around your limit string.
user@host> var="hello" user@host> cat <<LimitString user@host> echo $var user@host> LimitString echo hello user@host> cat <<'LimitString' user@host> echo $var user@host> LimitString echo $var
You can also use the following syntax to allow tab characters in front of each line. This is especially useful in scripting to allow indentation.
#!/bin/bash interactive-program <<-LimitString command #1 command #2 ... LimitString
Spaces have been used in this example due to the limitations of the Wiki editor, however it should be noted that this syntax only allows tab characters.
FAQ: How do I make EditPlus "correctly" highlight PHP heredoc strings?